4

Will this:

new java.util.Random(/* random seed */ 0)
new java.util.Random(/* random seed */ 1)

result in somehow "less random" / "more similar" random generators than this?

new java.util.Random(/* random seed */ 0)
new java.util.Random(/* random seed */ 1000)

In other words: do I risk having similar series of ints obtained from the random generators if their random seeds are similar?

Konrad Jamrozik
  • 3,254
  • 5
  • 29
  • 59
  • 5
    It's not "less" or "more" random. It's just differently random. – Louis Wasserman Jan 20 '16 at 19:26
  • 4
    You should really give [How good is java.util.Random](http://stackoverflow.com/questions/453479/how-good-is-java-util-random) a read. It discusses the strengths (no weak seeds) and weaknesses (not actually all that random) of the Random class. – azurefrog Jan 20 '16 at 19:33
  • 1
    https://stackoverflow.com/questions/12282628/why-are-initial-random-numbers-similar-when-using-similar-seeds should be mentioned here – wutzebaer Oct 02 '18 at 20:18

3 Answers3

4

No, similar seeds, will not produce similar random numbers.
Only same seeds will produce same numbers.

The code to set the seed is:

void setSeed(long seed) {
    this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1);
..}

This formula avoids that this.seed gets simlar values for the input seed value (used in the constructor, or by setSeed().

However there is some weakness, als explained in http://dontpanic.42.nl/2011/03/when-random-isn-as-random-as-expected.html

AlexWien
  • 28,470
  • 6
  • 53
  • 83
1

The state updates used to produce pseudo-random numbers are chaotic. Hence, using adjacent seed values results in entirely different state trajectories.

pjs
  • 18,696
  • 4
  • 27
  • 56
0

Random numbers are never random. They are entirely pre-defined and given the same seed will always result in the same numbers even over a million different runs of the commands, that is the reason they are called "Pseudorandom". The best thing to do is to seed with a value that will be different each time the program is run and can not be predicted easily such as the current time and date and/or number of clock cycles that have passed.

Nick Young
  • 197
  • 7
  • 2
    This was not the question. He wants to know if two adjacent seeds produce similar random numbers. – AlexWien Jan 20 '16 at 20:01
  • And I explained that they never produce random numbers. That is indeed an answer to the question. – Nick Young Jan 20 '16 at 21:15
  • 2
    Not it is not. You need to explain the effect of the input seed for two adjacent seed, and their effect, to the output random numbers. – AlexWien Jan 20 '16 at 21:17