Java – why do I use random run to get the same number?
•
Java
I'm following a book and in this Code:
Random rand = new Random(47); int i,j,k; j = rand.nextInt(100) + 1; System.out.println("j : " + j); k = rand.nextInt(100) + 1; System.out.println("k : " + k);
I have the same number in the output of this book, namely:
j : 59 k : 56
If I use
Random rand = new Random();
No 47 random class generates random numbers, it doesn't matter, but why if I put the number 47 into J = Rand nextInt(100)1; Why do I get the same book output? thank you
Solution
From documentation:
You can specify the seed in the constructor
You can also see: pseudorandom number generator – Wikipedia
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码