If I use the same initial value for Random in a java program and run it on two different machines, do I get the same set of numbers?
eg
long seed = 123L;//may be taken from some database or something java.util.Random ran = new java.util.Random(seed); int ret = 0; for (int i= 0; i< 10; i++){ ret = ran.nextInt(1000); System.out.println("ret="+ret); }
I always get
ret=782 ret=450 ret=176 ret=789 ret=795 ret=657 ret=834 ret=837 ret=585 ret=453
If I ran this several times on my computer , I would get the same set of numbers .. but suppose someone can get the secret value of the seed that I used (by guessing or from the secret location where it was saved) and run this code on his machine , will he get the same set of numbers?
damon
source share