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
400
データサイエンス13_解析.pdf
jnlp
0
510
データサイエンス12_分類.pdf
jnlp
0
360
データサイエンス11_前処理.pdf
jnlp
0
480
Recurrent neural network based language model
jnlp
0
140
自然言語処理研究室 研究概要(2012年)
jnlp
0
150
自然言語処理研究室 研究概要(2013年)
jnlp
0
110
自然言語処理研究室 研究概要(2014年)
jnlp
0
140
自然言語処理研究室 研究概要(2015年)
jnlp
0
220
Other Decks in Programming
See All in Programming
Vibe codingでおすすめの言語と開発手法
uyuki234
0
220
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
230
Basic Architectures
denyspoltorak
0
660
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
240
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
120
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
890
Architectural Extensions
denyspoltorak
0
270
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
6
1.8k
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
Optimizing for Happiness
mojombo
379
71k
Why Our Code Smells
bkeepers
PRO
340
58k
Deep Space Network (abreviated)
tonyrice
0
45
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
64
GitHub's CSS Performance
jonrohan
1032
470k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Producing Creativity
orderedlist
PRO
348
40k
So, you think you're a good person
axbom
PRO
2
1.9k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Rails Girls Zürich Keynote
gr2m
96
14k
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のいずれかの数字になる