Upgrade to Pro — share decks privately, control downloads, hide ads and more …

あなたの知らない乱数の世界

 あなたの知らない乱数の世界

リクルートテクノロジーズの社内勉強会で発表した乱数の話です。

Yosuke Furukawa

August 18, 2017
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. ͜͜Ͱ͍͏Randͱ͸ • ͓ͦΒ͘ MySQL ͔ Java ͔ͳʹ͔ͷ random ؔ਺ʁ •

    ͩͱͨ͠ΒϥϯμϜ͡Όͳ͍ͱ͸ݴΘͳ͍͕
 ࣭ͷѱ͍ϥϯμϜؔ਺Ͱ͋Δ͜ͱ͸͔֬ɻ
  2. ͜͜Ͱ͍͏Randͱ͸ • ͓ͦΒ͘ MySQL ͔ Java ͔ͳʹ͔ͷ random ؔ਺ʁ •

    ͩͱͨ͠ΒϥϯμϜ͡Όͳ͍ͱ͸ݴΘͳ͍͕
 ࣭ͷѱ͍ϥϯμϜؔ਺Ͱ͋Δ͜ͱ͸͔֬ɻ ϥϯμϜؔ਺ͷ࣭ͱ͸Կ͔ʁ
  3. ઢܗ߹ಉ๏ 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
  4. ઢܗ߹ಉ๏ 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 ໰୊ ۮ਺ ح਺ͷॱʹฒΜͰΔ
  5. ઢܗ߹ಉ๏ 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<> ॳظ஋ ͕ಉͩͬͨ͡Βඞͣಉ͡഑ྻ͕࡞ΒΕΔ
  6. ઢܗ߹ಉ๏ 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஋ͱ΋ݴ͏
  7. ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod

    M • ໰୊1 : ۮ਺ح਺ͷॱংͰฒͿ • ໰୊2 : ࠷ॳͷX[0](ॳظ஋) ͕ಉͩͬͨ͡Βඞ ͣಉ͡഑ྻ͕࡞ΒΕΔ
  8. ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod

    M • ໰୊1 : ۮ਺ح਺ͷॱংͰฒͿ • ໰୊2 : ࠷ॳͷX[0](ॳظ஋) ͕ಉͩͬͨ͡Βඞ ͣಉ͡഑ྻ͕࡞ΒΕΔ ࣍ͷཚ਺͕༧ଌͰ͖Δɻ ཚ਺ʹنଇੑ͕͋Δɻ
  9. ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod

    M • ໰୊1 : ۮ਺ح਺ͷॱংͰฒͿ • ໰୊2 : ࠷ॳͷX[0](ॳظ஋) ͕ಉͩͬͨ͡Βඞ ͣಉ͡഑ྻ͕࡞ΒΕΔ ࣍ͷཚ਺͕༧ଌͰ͖Δɻ ཚ਺ʹنଇੑ͕͋Δɻ ղ๏ΑΓΑ͍ΞϧΰϦζϜΛબͿ -JLFϝϧηϯψɾπΠελ 9034IJGU
  10. ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod

    M • ໰୊1 : ۮ਺ح਺ͷॱংͰฒͿ • ໰୊2 : ࠷ॳͷX[0](ॳظ஋) ͕ಉͩͬͨ͡Βඞ ͣಉ͡഑ྻ͕࡞ΒΕΔ TFFEͱճ਺͑͞෼͔Ε͹ ࣍ͷཚ਺͕༧ଌՄೳ
  11. ઢܗ߹ಉ๏ • X[n+1] = a * X[n] + b mod

    M • ໰୊1 : ۮ਺ح਺ͷॱংͰฒͿ • ໰୊2 : ࠷ॳͷX[0](ॳظ஋) ͕ಉͩͬͨ͡Βඞ ͣಉ͡഑ྻ͕࡞ΒΕΔ TFFEͱճ਺͑͞෼͔Ε͹ ࣍ͷཚ਺͕༧ଌՄೳ ٙࣅཚ਺ͱ͍͏ͷ͸جຊ͜͏͍͏΋ͷ