Is the difference between random seeds important?

Will it be:

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

leads to some kind of “less random” / “more like” random generators than this?

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

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

+4
source share
3 answers

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

Code for setting the seed:

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

This formula avoids this.seedgetting simlar values ​​for the input seed value (used in the constructor or setSeed ().

, http://dontpanic.42.nl/2011/03/when-random-isn-as-random-as-expected.html

+4

, , . , .

+1

Random numbers are never random. They are completely predetermined and, given the same seed, will always have the same numbers, even more than a million different runs of commands, so they are called "pseudo-random" . It is best to make seeds with a value that will differ each time the program starts and cannot be easily predicted, for example, the current time and date and / or the number of clock cycles passed.

0
source

Source: https://habr.com/ru/post/1625189/


All Articles