谁能说出为什么此Java代码返回这么多相同的MD5值:
public static void main(String[] args) throws Exception{
Random rnd = new Random();
for (int i = 0; i < 1000; i++) {
String key = DigestUtils.md5Hex(rnd.nextFloat() + System.currentTimeMillis() + "");
System.out.println(key + ", " + rnd.nextFloat() + System.currentTimeMillis() + "");
}
}
这是我得到的输出:
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.15059251440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.599991561440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.54911111440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.0982222561440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.169987141440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.032851281440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.223390041440334190624
814788aa9b6a22bf73ff3ae5fe0c6e0c, 0.70173611440334190624
....
....
....
最佳答案
对不起这是我的错 :)
显然:
rnd.nextFloat() + System.currentTimeMillis()
只需将两个数字相加即可得出一个很小的数字,该数字在Java中表示为同一字符串。
关于java - DigestUtils.md5Hex返回相同的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32166872/