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.4k
基礎情報処理演習(補足)乱数の生成
自然言語処理研究室
December 07, 2012
Tweet
Share
More Decks by 自然言語処理研究室
See All by 自然言語処理研究室
データサイエンス14_システム.pdf
jnlp
0
330
データサイエンス13_解析.pdf
jnlp
0
380
データサイエンス12_分類.pdf
jnlp
0
290
データサイエンス11_前処理.pdf
jnlp
0
400
Recurrent neural network based language model
jnlp
0
100
自然言語処理研究室 研究概要(2012年)
jnlp
0
100
自然言語処理研究室 研究概要(2013年)
jnlp
0
69
自然言語処理研究室 研究概要(2014年)
jnlp
0
64
自然言語処理研究室 研究概要(2015年)
jnlp
0
120
Other Decks in Programming
See All in Programming
Front-end application development, Symfony-style(s)
dunglas
2
1.9k
Designing for tomorrow's programming workflows
honnibal
PRO
2
120
Netty Chicago Java User Group 2024-04-17
sullis
0
170
HUIT新歓2024「競技プログラミング、やってみませんか?」
slephy2784
1
260
見た目から始める生産性向上
ikumatadokoro
7
760
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
620
Ruby Pattern Matching
bkuhlmann
0
920
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
670
Anthropic Cookbook のおすすめレシピ
schroneko
6
680
try!Swift Tokyo 2024 参加報告 LT
akidon0000
1
210
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
400
Rethinking UI building strategies @ SFI 2024
letelete
0
270
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
12
4.6k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
How STYLIGHT went responsive
nonsquared
92
4.8k
Building Your Own Lightsaber
phodgson
98
5.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
The MySQL Ecosystem @ GitHub 2015
samlambert
242
12k
The Language of Interfaces
destraynor
151
23k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
119
39k
Debugging Ruby Performance
tmm1
70
11k
The Brand Is Dead. Long Live the Brand.
mthomps
48
28k
Art, The Web, and Tiny UX
lynnandtonic
288
19k
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のいずれかの数字になる