Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
基礎情報処理演習(補足)乱数の生成
Search
自然言語処理研究室
December 07, 2012
Programming
0
1.5k
基礎情報処理演習(補足)乱数の生成
自然言語処理研究室
December 07, 2012
Tweet
Share
More Decks by 自然言語処理研究室
See All by 自然言語処理研究室
データサイエンス14_システム.pdf
jnlp
0
380
データサイエンス13_解析.pdf
jnlp
0
470
データサイエンス12_分類.pdf
jnlp
0
330
データサイエンス11_前処理.pdf
jnlp
0
450
Recurrent neural network based language model
jnlp
0
130
自然言語処理研究室 研究概要(2012年)
jnlp
0
130
自然言語処理研究室 研究概要(2013年)
jnlp
0
93
自然言語処理研究室 研究概要(2014年)
jnlp
0
110
自然言語処理研究室 研究概要(2015年)
jnlp
0
180
Other Decks in Programming
See All in Programming
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
860
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
950
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
230
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
430
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
1
550
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
190
FormFlow - Build Stunning Multistep Forms
yceruto
1
190
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
260
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
110
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
380
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
173
14k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
790
Unsuck your backbone
ammeep
671
58k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
RailsConf 2023
tenderlove
30
1.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
GraphQLとの向き合い方2022年版
quramy
48
14k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Designing for humans not robots
tammielis
253
25k
Gamification - CAS2011
davidbonilla
81
5.3k
Transcript
基礎情報処理演習(補足) 乱数の生成 山本和英 長岡技術科学大学 1
プログラム例の前に... • 乱数と言っても、任意の数が本当に無作為 で生成されるわけではなく、あらかじめ用意 されている(一見ばらばらのように見える)整 数列が順に表示されるだけである(疑似乱 数)。よって、いつかは表示が1周する。 • 疑似乱数は、数字列のどこから表示を始め るかを最初に決める必要がある(これを決め
ないと毎回同じ数字が生成され、乱数にな らない)。これを乱数の種(seed)と呼ぶ。 2
プログラム例1: 0~1の乱数を生成 #include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> void
main(void){ double p; srand(time(NULL)); p = (double) rand() / RAND_MAX; printf (“%f\n”, p); } 3
プログラム例1: 0~1の乱数を生成 #include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> void
main(void){ double p; srand(time(NULL)); p = (double) rand() / RAND_MAX; printf (“%f\n”, p); } 4 乱数の種を(プログラム 開始時刻で)決める。 最初に1回だけ実行する time関数のために必要
プログラム例1: 0~1の乱数を生成 #include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> void
main(void){ double p; srand(time(NULL)); p = (double) rand() / RAND_MAX; printf (“%f\n”, p); } 5 乱数(0~RAND_MAX間の ある整数)を生成する。 毎回数字が変わる。 srand関数とrand関数 のために必要
プログラム例1: 0~1の乱数を生成 #include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> void
main(void){ double p; srand(time(NULL)); p = (double) rand() / RAND_MAX; printf (“%f\n”, p); } 6 rand関数が生成する最大値 RAND_MAXが定義されている
プログラム例2:サイコロ(1~6の乱数)を作る #include <stdio.h> #include <math.h> #include <time.h> void main(void){ int
k; srand(time(NULL)); k = rand() % 6 + 1; printf (“%d\n”, k); } 7 rand()%6 はある整数を 6で割った余りなので、 0~5のいずれかの数字になる