Tony Stark Tony Stark - 1 year ago 70
Java Question

struggling to understand Random class constructor with one parameter of long type

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, bt I'm really struggling to understand what it actually means. Could someone please kindly explain it to me in a way that's easier to understand? Thanks in advance for any help!

enter image description here

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download