Discuss / Java / 越是安全的算法速度越慢

越是安全的算法速度越慢

Topic source

灵逗士

#1 Created at ... [Delete] [Delete and Lock User]

计算几个随机数时用SecureRandom比Random明显慢了

Joker.fu_95

#2 Created at ... [Delete] [Delete and Lock User]

就普通安全随机数慢点,高强度安全随机数没觉得

廖雪峰

#3 Created at ... [Delete] [Delete and Lock User]

SecureRandom.getInstanceStrong()在容器和某些虚拟机中可能因为随机熵不够导致超时

有个问题想请教一下廖老师

byte[] a = {1, 2};SecureRandom sr = new SecureRandom(a);System.out.println(sr.nextInt(100));for (int i = 0; i < 10; i++) {    System.out.println(sr.nextInt(100));}

我根据以上代码得出的数也是确定的,和伪随机Random的效果一样,这是为什么?不是说SecureRandom是安全随机数吗?我很不理解所以然。

廖雪峰

#5 Created at ... [Delete] [Delete and Lock User]

首先,你要确认运行的代码是当前代码编译的


  • 1

Reply