Is there a way to guess the next number java random? [duplicate]

浪子不回头ぞ 提交于 2020-01-06 20:19:45

问题


Question is in the title, quite new here so don't know much about the site yet. Want to use hash for creating "more randomness" but not yet sure about Java's Math.Random() yet, is it possible to crack it?


回答1:


If you are using java.util.Random(), it is possible. Have a look at this Code

For better security, you have to use SecureRandom as below

SecureRandom secureRandomGenerator = SecureRandom.getInstance("SHA1PRNG");

But the best solution, which can't be cracked is using Hardware for Random number generation.

EDIT:

Algorithms based on Random like MersenneTwister can be hacked as per this article by Dan Petro

CSPRNGs (Cryptographically secure pseudorandom number generator) to use are:

  1. Reading from /dev/urandom on a Unix-like system

  2. The Java SecureRandom class

  3. The .NET RNGCryptoServiceProvider class

  4. The PHP openssl_random_pseudo_bytes() function

In contrast, some examples of random number generators to avoid are:

  1. The libc rand() function

  2. The Java Random class

  3. The .NET Random class

  4. PHP’s rand() and mt_rand() functions

Have a look at this article by Thomas Huhn



来源:https://stackoverflow.com/questions/33035721/is-there-a-way-to-guess-the-next-number-java-random

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!