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
Yosuke Furukawa
PRO
August 18, 2017
Programming
0
170
あなたの知らない乱数の世界
リクルートテクノロジーズの社内勉強会で発表した乱数の話です。
Yosuke Furukawa
PRO
August 18, 2017
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
0
140
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
150
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
340
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
700
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.3k
Other Decks in Programming
See All in Programming
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
120
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
200
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Better Code Design in PHP
afilina
PRO
0
130
Jakarta EE meets AI
ivargrimstad
0
800
Realtime API 入門
riofujimon
0
150
Functional Event Sourcing using Sekiban
tomohisa
0
110
rails new flags - `rails new` のフラグから Rails を構成するコンポーネントの変遷をザックリ眺める
snaka
0
1.8k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
350
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
For a Future-Friendly Web
brad_frost
175
9.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Building Adaptive Systems
keathley
38
2.3k
Why Our Code Smells
bkeepers
PRO
334
57k
How GitHub (no longer) Works
holman
310
140k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Facilitating Awesome Meetings
lara
50
6.1k
What's new in Ruby 2.0
geeforr
343
31k
Visualization
eitanlees
145
15k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Transcript
͋ͳͨͷΒͳ͍ ཚͷੈք 2017/08/18 @ Recruit Tech Study
ͱཚ
ͦͦͷൃ
ৄ͍͠ܦҢͪ͜ΒΛ
RandඍົʹϥϯμϜ͡Όͳ͍ʁ
͜͜Ͱ͍͏Randͱ • ͓ͦΒ͘ MySQL ͔ Java ͔ͳʹ͔ͷ random ؔʁ •
ͩͱͨ͠ΒϥϯμϜ͡Όͳ͍ͱݴΘͳ͍͕ ࣭ͷѱ͍ϥϯμϜؔͰ͋Δ͜ͱ͔֬ɻ
͜͜Ͱ͍͏Randͱ • ͓ͦΒ͘ MySQL ͔ Java ͔ͳʹ͔ͷ random ؔʁ •
ͩͱͨ͠ΒϥϯμϜ͡Όͳ͍ͱݴΘͳ͍͕ ࣭ͷѱ͍ϥϯμϜؔͰ͋Δ͜ͱ͔֬ɻ ϥϯμϜؔͷ࣭ͱԿ͔ʁ
JavaͰMath.random() ͬͯ·͔͢ʁ
Math.random() ʹද͞ΕΔ ཚൃੜثٙࣅཚͰ͋Γɺ Javaͷٖࣅཚͷ࣮ ઢܗ߹ಉ๏
Javaͷ Math.random ͷΞϧΰ ϦζϜઢܗ߹ಉ๏ • "ܭࢉ୯७͕ͩ͋Μ·ΓϥϯμϜ͡Όͳ͍ཚ ੜث" • X[n+1] =
a * X[n] + b mod M
ઢܗ߹ಉ๏ const A = 1103515245 const B = 12345 const
M = 2^32 var X function rand() { X = (A * X + B) % M return X } // 32,21,18,11,6,17,20,27,32,21,18
ઢܗ߹ಉ๏ const A = 1103515245 const B = 12345 const
M = 2^32 var X function rand() { X = (A * X + B) % M return X } // 32,21,18,11,6,17,20,27,32,21,18 ۮ حͷॱʹฒΜͰΔ
ઢܗ߹ಉ๏ const A = 1103515245 const B = 12345 const
M = 2^32 var X function rand() { X = (A * X + B) % M return X } // 32,21,18,11,6,17,20,27,32,21,18 ۮ حͷॱʹฒΜͰΔ ࠷ॳͷ9<> ॳظ ͕ಉͩͬͨ͡Βඞͣಉ͡ྻ͕࡞ΒΕΔ
ઢܗ߹ಉ๏ const A = 1103515245 const B = 12345 const
M = 2^32 var X function rand() { X = (A * X + B) % M return X } // 32,21,18,11,6,17,20,27,32,21,18 ۮ حͷॱʹฒΜͰΔ ࠷ॳͷ9<> ॳظ ͕ಉͩͬͨ͡Βඞͣಉ͡ྻ͕࡞ΒΕΔ TFFEͱݴ͏
ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod
M • 1 : ۮحͷॱংͰฒͿ • 2 : ࠷ॳͷX[0](ॳظ) ͕ಉͩͬͨ͡Βඞ ͣಉ͡ྻ͕࡞ΒΕΔ
ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod
M • 1 : ۮحͷॱংͰฒͿ • 2 : ࠷ॳͷX[0](ॳظ) ͕ಉͩͬͨ͡Βඞ ͣಉ͡ྻ͕࡞ΒΕΔ ࣍ͷཚ͕༧ଌͰ͖Δɻ ཚʹنଇੑ͕͋Δɻ
ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod
M • 1 : ۮحͷॱংͰฒͿ • 2 : ࠷ॳͷX[0](ॳظ) ͕ಉͩͬͨ͡Βඞ ͣಉ͡ྻ͕࡞ΒΕΔ ࣍ͷཚ͕༧ଌͰ͖Δɻ ཚʹنଇੑ͕͋Δɻ ղ๏ΑΓΑ͍ΞϧΰϦζϜΛબͿ -JLFϝϧηϯψɾπΠελ 9034IJGU
ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod
M • 1 : ۮحͷॱংͰฒͿ • 2 : ࠷ॳͷX[0](ॳظ) ͕ಉͩͬͨ͡Βඞ ͣಉ͡ྻ͕࡞ΒΕΔ TFFEͱճ͔͑͞Ε ࣍ͷཚ͕༧ଌՄೳ
ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod
M • 1 : ۮحͷॱংͰฒͿ • 2 : ࠷ॳͷX[0](ॳظ) ͕ಉͩͬͨ͡Βඞ ͣಉ͡ྻ͕࡞ΒΕΔ TFFEͱճ͔͑͞Ε ࣍ͷཚ͕༧ଌՄೳ ٙࣅཚͱ͍͏ͷجຊ͜͏͍͏ͷ
randomؔͷ࣭ͱ • ٖࣅཚͰ͋Δ߹ɺཚ͕Ұ༷ʹ͢Δ ͜ͱʢಉ͡ࣈ͕ग़ʹ͍͘͜ͱʣ • نଇੑ͕ͳ͍͜ͱʢۮɾح͕ަޓʹग़ͨ Γ͠ͳ͍͜ͱʣ
randomؔͷ࣭ͱ • ٖࣅཚͰ͋Δ߹ɺཚ͕Ұ༷ʹ͢Δ ͜ͱʢಉ͡ࣈ͕ग़ʹ͍͘͜ͱʣ • نଇੑ͕ͳ͍͜ͱʢۮɾح͕ަޓʹग़ͨ Γ͠ͳ͍͜ͱʣ ࣭ͷྑ͍ϥϯμϜؔʢҰ༷ʹཚ͕͠ɺपظੑ͕͘ɺنଇੑ͕ͳ͍ͷʣ ͷྫɿϝϧηϯψɾπΠελɺ9034IJGU
randomؔͷ࣭ͱ • ٖࣅཚͰ͋Δ߹ɺཚ͕Ұ༷ʹ͢Δ ͜ͱʢಉ͡ࣈ͕ग़ʹ͍͘͜ͱʣ • نଇੑ͕ͳ͍͜ͱʢۮɾح͕ަޓʹग़ͨ Γ͠ͳ͍͜ͱʣ ࣭ͷྑ͍ϥϯμϜؔʢҰ༷ʹཚ͕͠ɺपظੑ͕͘ɺنଇੑ͕ͳ͍ͷʣ ͷྫɿϝϧηϯψɾπΠελɺ9034IJGU
randomؔͷ࣭ͱ • ٖࣅཚͰ͋Δ߹ɺཚ͕Ұ༷ʹ͢Δ ͜ͱʢಉ͡ࣈ͕ग़ʹ͍͘͜ͱʣ • نଇੑ͕ͳ͍͜ͱʢۮɾح͕ަޓʹग़ͨ Γ͠ͳ͍͜ͱʣ ࣭ͷྑ͍ϥϯμϜؔʢҰ༷ʹཚ͕͠ɺपظੑ͕͘ɺنଇੑ͕ͳ͍ͷʣ ͷྫɿϝϧηϯψɾπΠελɺ9034IJGU ͪͳΈʹ7ͷ.BUISBOEPN
͜ͷ9034IJGU
͞Βʹຊ
ݫີʹϥϯμϜͳrandomؔͱ͔ͳ͍?
ຊͩΖ͏͔ʁ
ٙࣅ͡Όͳ͍ཚ͋Δ • ϋʔυΣΞཚੜثʢӳޠͩͱTrue Random Number Generator TRNG) • /dev/random •
ࡶԻ • ์ࣹੑ࣭ͷ่յ • ͳͲͳͲɺଞʹͨ͘͞Μ͋Δ
/dev/random ΩʔϘʔυϚεɺσΟεΫૢ࡞ͱ͍ͬͨૢ࡞هΛݩʹ৭Μͳ ใΛஷΊ͓͖ͯɺ͔ͦ͜ΒϥϯμϚΠζ͞ΕͨใΛग़͢
/dev/random ΩʔϘʔυϚεɺσΟεΫૢ࡞ͱ͍ͬͨૢ࡞هΛݩʹ৭Μͳ ใΛஷΊ͓͖ͯɺ͔ͦ͜ΒϥϯμϚΠζ͞ΕͨใΛग़͢ ૢ࡞ه͕Ұఆஷ·Βͳ͍ͱ ػೳ͠ͳ͍
ࡶԻΛͬͨํ๏ ిؾճ࿏Ͱ0/Ͱ0''Ͱͳ͍ঢ়گΛ࡞͓ͬͯ͘ɻ ͦͷ্ͰࡶԻͱ͍͏ཧݱΛͬͯPS͕ϥϯμϜʹग़ΔΑ͏ʹ͢Δɻ )JHI )JHI
ࡶԻΛͬͨํ๏ *OUFM*WZ#SJEHFʹ࣮ࡁΈɻ
ࡶԻΛͬͨํ๏ *OUFM*WZ#SJEHFʹ࣮ࡁΈɻ ͨͩ͠ɺࡶԻʹΑΔํ๏ిྗফඅྔ͕ܹ͍͠ ΤωϧΪʔ͕খ͗ͯ͢͞ภΓ͕͋ΔɺͦͷͨΊιϑτΣΞͷิॿ͕ඞཁ
ݪࢠ่֩յΛͬͨํ๏
ݪࢠ่֩յΛͬͨํ๏ ”70ஹݸͷݪࢠͷݪࢠ่֩յΛར༻ͨ͠ͷͰɺߏ୯७ɻ” ”ઢݯͷۙ͘ʹμΠΦʔυΛઃஔ͠ɺ͜͜ͰύϧεΛݕ͢Δɻ”
ݪࢠ่֩յΛͬͨํ๏ ”70ஹݸͷݪࢠͷݪࢠ่֩յΛར༻ͨ͠ͷͰɺߏ୯७ɻ” ”ઢݯͷۙ͘ʹμΠΦʔυΛઃஔ͠ɺ͜͜ͰύϧεΛݕ͢Δɻ”
ʊਓਓਓਓਓʊ ʼɹύϧεɹʻ ʉY^Y^Y^Yʉ
͑ɺͦΕඃരɾɾɾ
ඃര͠ͳ͕ΒཚΛऔΔͷ ࠷ߴʹϩοΫ
"ݪࢠ่֩յͱ͍͏ͱɺ์ࣹઢ ඃΛࢥ͍ු͔ͯ͠·͏͕ɺ ઢྔݶΓͳ͘͘ɺਓମʹ Өڹ͢ΔϨϕϧͰͳ͍ɻ"
·ͱΊ • ཚܯ • ٖࣅཚͷྑ͠ѱ͠ • ϋʔυΣΞཚੜثͱ͍͏ਅͷཚΛ࡞ Δͷ͋Δ • ཚԞਂ͍ɺΈΜͳ৭ʑௐͯΈΔͱָ͍͠