问题描述
问题在标题中,这里很新,所以对这个网站还不太了解.想使用 hash 来创造更多的随机性"但还不确定 Java 的 Math.Random() 是否有可能破解它?
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?
推荐答案
如果你正在使用 java.util.Random()
,这是可能的.看看这个代码
If you are using java.util.Random()
, it is possible. Have a look at this Code
为了更好的安全性,你必须使用 SecureRandom
如下
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.
像 MersenneTwister 这样的基于 Random 的算法可以被黑客攻击 Dan Petro
Algorithms based on Random like MersenneTwister can be hacked as per this article by Dan Petro
CSPRNGs
(密码安全伪随机数生成器)是:
CSPRNGs
(Cryptographically secure pseudorandom number generator) to use are:
在类 Unix 系统上从
/dev/urandom
读取
Java SecureRandom
类
.NET RNGCryptoServiceProvider
类
PHP openssl_random_pseudo_bytes()
函数
相比之下,要避免的随机数生成器的一些示例是:
In contrast, some examples of random number generators to avoid are:
libc rand()
函数
Java Random 类
The Java Random class
.NET Random 类
The .NET Random class
PHP 的 rand()
和 mt_rand()
函数
PHP’s rand()
and mt_rand()
functions
看看这篇由 Thomas Huhn 撰写的文章
Have a look at this article by Thomas Huhn
这篇关于有没有办法猜测下一个数字java随机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!