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
Satoshi SAKAO
September 05, 2018
Science
0
180
乱数を作る
社内のLTイベント「えるLT Vol3」で発表した資料です
Satoshi SAKAO
September 05, 2018
Tweet
Share
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Testcontainers/2024-11-20-llt32
ottijp
0
72
Pkl/2024-04-17-llt31
ottijp
0
100
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
170
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
300
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
170
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
190
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
170
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
110
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
110
Other Decks in Science
See All in Science
生成検索エンジン最適化に関する研究の紹介
ynakano
2
1.5k
知能とはなにかーヒトとAIのあいだー
tagtag
PRO
0
130
機械学習 - 決定木からはじめる機械学習
trycycle
PRO
0
1.2k
AI(人工知能)の過去・現在・未来 —AIは人間を超えるのか—
tagtag
PRO
1
230
NASの容量不足のお悩み解決!災害対策も兼ねた「Wasabi Cloud NAS」はここがスゴイ
climbteam
1
310
デジタルアーカイブの教育利用促進を目指したメタデータLOD基盤に関する研究 / Research on a Metadata LOD Platform for Promoting Educational Uses of Digital Archives
masao
0
140
Accelerating operator Sinkhorn iteration with overrelaxation
tasusu
0
160
俺たちは本当に分かり合えるのか? ~ PdMとスクラムチームの “ずれ” を科学する
bonotake
2
1.1k
Collective Predictive Coding as a Unified Theory for the Socio-Cognitive Human Minds
tanichu
0
150
データベース15: ビッグデータ時代のデータベース
trycycle
PRO
0
420
Optimization of the Tournament Format for the Nationwide High School Kyudo Competition in Japan
konakalab
0
140
(メタ)科学コミュニケーターからみたAI for Scienceの同床異夢
rmaruy
0
150
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
2.8k
Designing Powerful Visuals for Engaging Learning
tmiket
0
200
A Soul's Torment
seathinner
4
2.1k
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
400
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
430
How to Think Like a Performance Engineer
csswizardry
28
2.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
200
Design in an AI World
tapps
0
120
Designing for humans not robots
tammielis
254
26k
Transcript
乱数を作る えるLT Vol.3 2018/09/05 (Wed) @インフォコム Satoshi SAKAO K1
話すひと K2 インフォコム株式会社 オープンイノベーションセンター " アプリケーションエンジニア JS(ES6) / Node.js /
GCP / IoT / iOS (Swift) シュタゲ / ASMR Satoshi SAKAO @ottijp
免責 K3 • 実はよくわかってません • 数学不得意です • Newtonに感化された だけなんです
ランダムな点群はどっち? K4 A B クラスター錯覚
ランダムな数(乱数)をどう作るか? • プログラミングにおける rand() • 計算式(アルゴリズム)によって次の乱数を決める • 規則がいっさい存在しない •
ノイズ,熱雑音などによって次の乱数を決める K5 疑似乱数 真の乱数
疑似乱数 弱い乱数 • 計算は簡単(早い) • 収束,周期性がある (乱数として質が悪い) 強い乱数 • 計算は比較的遅い
• 乱数としての質が良い K6 • 平方採中法 • 線形合同法 • clangのrand() • Javaのjava.util.Random • XOR Shift • JavaScriptのMath.random() • メルセンヌ・ツイスタ • さいきょう
疑似乱数の比較 K7 線形合同法(弱い乱数) メルセンヌ・ツイスタ(強い乱数) ※ [0:255]の範囲で整数乱数を生成し,(x,y,z)点を1000点作成
ランダムな数(乱数)をどう作るか? • プログラミングにおける rand() • 計算(アルゴリズム)によって次の乱数を決める • 規則がいっさい存在しない •
ノイズ,熱雑音などによって次の乱数を決める K8 疑似乱数 真の乱数
真の乱数 • サイコロ • /dev/random デバイスドライバなどから集めた環境ノイズを利用 • HW乱数生成装置 K9 統計数理研究所の乱数生成装置
真の乱数 K10 /dev/random(真の乱数) ※ [0:255]の範囲で整数乱数を生成し,(x,y,z)点を1000点作成
K11 真の乱数生成装置を作る
真の乱数生成装置を作る • Arduinoを利用 • analogRead()で開放端子から電圧を入力 • 一定間隔で計測した電圧デジタル値の1bitを合成 K12 開放 (繋がない)
真の乱数生成装置を作る K13 0x10000010 •2.34V 479 0x11011111 •2.28V 466 0x11010010 •2.21V
452 0x11000100 •2.09V 428 0x10101100 •1.95V 400 0x10010000 •1.82V 372 0x01110100 •1.68V 345 0x01011001 •1.56V 320 0x01000000 by Morn https://commons.wikimedia.org/wiki/User:Morn
Arduino電圧乱数 K14 メルセンヌ・ツイスタ(強い疑似乱数) /dev/random(真の乱数) Arduino電圧乱数
Arduino電圧乱数 • 精度が悪い理由(予想) • 電圧の振幅が小さい • ランダム性の無いノイズの可能性 • 生成スピードが遅い(125B/s) •
電圧計測間隔が短いと似通った値になった • それっぽい値になるように1msに1bit計測 K15
乱数の精度検定 • 検定内容 • 等確率性 • 無規則性 • 検定用のツールがある •
dieharderなど • https://webhome.phy.duke.edu/~rgb/General/ dieharder.php • なんかうまく検定評価できず挫折 orz K16
まとめ • 乱数の種類 • 疑似乱数と真の乱数 • よりよい精度には強い乱数 (メルセンヌ・ツイスタなど)を使おう • 真の乱数を手軽に使うには/dev/randomを使おう
• 精度は悪いが自作もできる K17
$ exit K18
K19 Appendix
Arduinoのコード K20