I sowed my safe random object with a long number. Now I want to extract another long number. But there is only a function called nextBytes(byte[] b) that gives a random byte[] .
Is there any way to get a long number?
SecureRandom ranGen1 = new SecureRandom(); ranGen1.setSeed(1000); SecureRandom ranGen2 = new SecureRandom(); ranGen2.setSeed(1000); byte[] b1= new byte[3]; byte[] b2=new byte[3]; ranGen1.nextBytes(b1); ranGen2.nextBytes(b2); int a1=b1[0]; int a2=b1[1]; int a3=b1[2]; int c1=b2[0]; int c2=b2[1]; int c3=b2[2]; System.out.println(a1+", "+a2+", "+a3);
System.out.println (ranGen2.nextLong ()); // generated by ranGen2
result:
4, -67, 69 4, -67, 69 -3292989024239613972 //this is using nextLong() -3292989024239613972
Result for Peter Lowry code: (Using safe random)
-7580880967916090810 -7580880967916090810 7364820596437092015 7364820596437092015 6152225453014145174 6152225453014145174 6933818190189005053 6933818190189005053 -2602185131584800869 -2602185131584800869 -4964993377763884762 -4964993377763884762 -3544990590938409243 -3544990590938409243 8725474288412822874 8725474288412822874 -8206089057857703584 -8206089057857703584 -7903450126640733697 -7903450126640733697
They are superior to the same. How can you get different numbers?
This is the result that I get after using the second update of Peter Lawrey (I am using the Windows operating system and it seems to be using a different operating system that created the confusion)
SHA1PRNG appears to produce the same values with the same seed The default PRNG on this system is SHA1PRNG
source share