I'm relatively new to java and is studying the random class in Java se8. I'm struggling to understand the random class constructor with one parameter of type long. I have attached a screen shot of the explanation in Java documentation, but I'm really struggling to understand what it actually means. Could someone please kindly explain it to me?
Asked
Active
Viewed 68 times
-1
-
1Well which bit of it don't you understand? Did you read the overview documentation which says a bit more about the seed? – Jon Skeet Jul 25 '16 at 05:56
-
1Wikipedia has a pretty nice definition of what a "seed" is in programming algorithms https://en.wikipedia.org/wiki/Random_seed – ichthyocentaurs Jul 25 '16 at 05:58
1 Answers
1
A pseudorandom number generator does not actually create random numbers. Instead, it has an internal state and performs a calculation on it that produces a seemingly random number and updates the internal state (so that you get a different number the next time you ask the generator for one).
The sequence of numbers in completely determined by the internal state. In this case, it is a long
(for cryptographically strong PRNG it will be something bigger). For the same long
seed, you will get the same sequence of numbers back.
You might want to do that in order to reproduce a previous sequence exactly. If you don't care, you can leave the seed unspecified (in this case some default will be supplied that is different every time).

Thilo
- 257,207
- 101
- 511
- 656