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

#渋谷java あなたと乱数生成とJava

#渋谷java あなたと乱数生成とJava

第十回 #渋谷java http://shibuya-java.connpass.com/event/11574/ での発表資料です。Java で乱数生成するときのお話をしました。

KOMIYA Atsushi

March 07, 2015
Tweet

More Decks by KOMIYA Atsushi

Other Decks in Programming

Transcript

  1. ͋ͳͨͱཚ਺ੜ੒ͱ Java ୈेճ #ौ୩java 2015-03-07 @komiya_atsushi

  2. ͓·ͩΕ ʢ͓લ୭Αʁʣ

  3. ,0.*:""UTVTIJ [email protected]

  4. None
  5. Ad server and machine learning with Java

  6. Random Number Generator

  7. java.util.Random

  8. None
  9. Random classes provided by JDK

  10. Random classes provided by JDK • java.util.Random • java.security.SecureRandom •

    SecureRandom.getInstance("SHA1PRNG")   • java.util.concurrent.ThreadLocalRandom • ThreadLocalRandom.current()
  11. Random classes provided by commons-math3

  12. Random classes provided by commons-math3 • MersenneTwister • most popular

    (?) random number generator • Well44497a • longer period than Mersenne Twister • ISAACRandom • a fast cryptographic pseudo-random number generator
  13. Random classes provided by commons-math3 • RandomDataGenerator supports sampling from

    various distributions • Beta / Binomial / Cauchy / ChiSquare / Exponential / F / Gamma / Hypergeometric / Pascal / Poisson / T / Weibull / Zipf • java.util.Random only supports sampling from Gaussian (normal distribution)
  14. Comparisons

  15. Concurrency of Random and ThreadLocalRandom

  16. Concurrency of Random and ThreadLocalRandom 5ISFBE-PDBM3BOEPNJTBXFTPNF

  17. Latency of 200,000,000 times random number generation

  18. Latency of 200,000,000 times random number generation .FSTFOOF5XJTUFS JTGBTU 3BOEPNJTOPU

    GBTU    
  19. Conclusion

  20. If you need… • high concurrency one • use ThreadLocalRandom

    • very long-period & high quality one • use Well44497a • long-period & fast one • use MersenneTwister • cryptographically secure one • use SecureRandom
  21. Thanks! Any questions?

  22. 8&`3&)*3*/( IUUQTKPCTGPSLXFMMDPNTNBSUOFXT PSDPOUBDUNF