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
490
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
高速開発のためのコード整理術
sutetotanuki
1
410
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1.1k
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
180
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
440
CSC307 Lecture 09
javiergs
PRO
1
840
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Apache Iceberg V3 and migration to V3
tomtanaka
0
180
CSC307 Lecture 04
javiergs
PRO
0
660
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
390
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
130
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
57
Building Flexible Design Systems
yeseniaperezcruz
330
40k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
3.9k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
110
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
430
Automating Front-end Workflow
addyosmani
1371
200k
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のいずれかの数字になる