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
1.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
基礎情報処理演習(補足)乱数の生成
自然言語処理研究室
December 07, 2012
More Decks by 自然言語処理研究室
See All by 自然言語処理研究室
データサイエンス14_システム.pdf
jnlp
0
420
データサイエンス13_解析.pdf
jnlp
0
530
データサイエンス12_分類.pdf
jnlp
0
370
データサイエンス11_前処理.pdf
jnlp
0
500
Recurrent neural network based language model
jnlp
0
170
自然言語処理研究室 研究概要(2012年)
jnlp
0
160
自然言語処理研究室 研究概要(2013年)
jnlp
0
130
自然言語処理研究室 研究概要(2014年)
jnlp
0
150
自然言語処理研究室 研究概要(2015年)
jnlp
0
230
Other Decks in Programming
See All in Programming
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.3k
関数型プログラミングのメリットって何だろう?
wanko_it
0
160
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
250
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
160
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
110
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.8k
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
280
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
150
フィードバックで育てるAI開発
kotaminato
1
110
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
250
Featured
See All Featured
Done Done
chrislema
186
16k
Designing for Performance
lara
611
70k
How to make the Groovebox
asonas
2
2.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
New Earth Scene 8
popppiees
3
2.4k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
The agentic SEO stack - context over prompts
schlessera
0
840
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
470
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.4k
How GitHub (no longer) Works
holman
316
150k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
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のいずれかの数字になる