Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
乱数を作る
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Satoshi SAKAO
September 05, 2018
Science
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
乱数を作る
社内のLTイベント「えるLT Vol3」で発表した資料です
Satoshi SAKAO
September 05, 2018
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Testcontainers/2024-11-20-llt32
ottijp
0
120
Pkl/2024-04-17-llt31
ottijp
0
130
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
200
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
360
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
190
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
230
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
190
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
130
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
130
Other Decks in Science
See All in Science
データベース12: 正規化(2/2) - データ従属性に基づく正規化
trycycle
PRO
0
1.8k
データベース04: SQL (1/3) 単純質問 & 集約演算
trycycle
PRO
0
1.8k
機械学習 - K近傍法 & 機械学習のお作法
trycycle
PRO
1
1.7k
生成AI時代のインタラクションサイエンス(招待講演)/interaction-science
okana2ki
0
110
Visual Linear Algebra - Lecture at Shosen Grande
hiranabe
0
630
チュートリアル:世界モデル
hf149
0
2.4k
データベース09: 実体関連モデル上の一貫性制約
trycycle
PRO
0
1.9k
Kritische evaluatie van GenAI-output voor literatuuronderzoek
voginip
0
250
Where does the rigor go? Research software and the future of trustworthy science.
arfon
0
350
Understanding CVP Waveforms: Interpretation and Clinical Implications in Anesthesiology
taka88
0
950
JSAI2026企画セッションKS-14 インタビュー集『⼈⼯知能と哲学と四つの問い』が提起する⼈⼯知能のこれからの課題 趣旨説明 / JSAI2026 Special Session: A Collection of Interviews, “Artificial Intelligence, Philosophy, and Four Questions”
ykiyota
0
470
20260410_SystemsThinking
takusamar
1
160
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
630
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
320
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Test your architecture with Archunit
thirion
2
2.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
270
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