I am a little curious what are the constant values (if they even are truly constant) used in java.util.Random
.
I used the method setSeed()
and give it a value of 3
and set the limit of the value it can generate to 5
or random.nextInt(5)
.
random.setSeed(3);
int[] n = new int[5];
for(int i = 0; i < n.length; i++) {
n[i] = random.nextInt(5);
}
The numbers generated are 4, 0, 0, 1, 3
. I know that the java.util.Random
uses the linear congruential number generator to generate random numbers.
Xn+1 = (aXn + c) mod m
Now, how can I trace back or find the values used in the linear number congruential generator. I know that the Xn value is the seed value I put, which is in this case is 3
. How can I find the value of m, a, and the c?
Aucun commentaire:
Enregistrer un commentaire