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
基礎情報処理演習(補足)乱数の生成
自然言語処理研究室
December 07, 2012
More Decks by 自然言語処理研究室
See All by 自然言語処理研究室
データサイエンス14_システム.pdf
jnlp
0
410
データサイエンス13_解析.pdf
jnlp
0
530
データサイエンス12_分類.pdf
jnlp
0
370
データサイエンス11_前処理.pdf
jnlp
0
490
Recurrent neural network based language model
jnlp
0
160
自然言語処理研究室 研究概要(2012年)
jnlp
0
160
自然言語処理研究室 研究概要(2013年)
jnlp
0
120
自然言語処理研究室 研究概要(2014年)
jnlp
0
140
自然言語処理研究室 研究概要(2015年)
jnlp
0
230
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
430
ローカルLLMでどこまでコードが書けるか / How much code can be written on a local LLM
kishida
2
340
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
260
【26新卒研修資料】TDD実装演習
dip_tech
PRO
0
180
AI-DLC Deep Dive
yuukiyo
9
5.7k
【26新卒研修】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
150
認証統合から始めるフロントエンドの機能単位開発 — マイクロサービス思想の適用
koukimiura
0
100
🦞OpenClaw works with AWS
licux
1
350
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
140
AIと共に生きる技術選定 2026
sgash708
0
130
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
770
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
70
39k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
130
Accessibility Awareness
sabderemane
1
110
Art, The Web, and Tiny UX
lynnandtonic
304
21k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.4k
4 Signs Your Business is Dying
shpigford
187
22k
Done Done
chrislema
186
16k
The Cost Of JavaScript in 2023
addyosmani
55
9.9k
How GitHub (no longer) Works
holman
316
150k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
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のいずれかの数字になる