越是安全的算法速度越慢
Topic source有个问题想请教一下廖老师
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是安全随机数吗?我很不理解所以然。
他源码里面有这个可以带参的构造方法,不知道是不是种子?
public SecureRandom(byte[] seed) { super(0); getDefaultPRNG(true, seed); this.threadSafe = getThreadSafe();}
- 1
灵逗士
计算几个随机数时用SecureRandom比Random明显慢了