How different do random seeds need to be?
Asked Answered
C

6

19

Consider code like this (Python):

import random

for i in [1, 2, 3, 4]:
    random.seed(i)
    randNumbers = [random.rand() for i in range(100)] # initialize a list with 100 random numbers
    doStuff(randNumbers)

I want to make sure that randNumbers differ significantly from one call to another. Do I need to make sure the seed numbers differ significantly between the subsequent calls, or is it sufficient that the seeds are different (no matter how)?

To the pedants: please realize the above code is super-over-simplified

Chester answered 12/10, 2009 at 14:39 Comment(2)
"differ significantly", in the context of random number generators, could mean many different things. Are there specific tests of randomness you are looking pass and aren't currently? Typical PRNGs have periods much, much longer than 100 numbers. Usually one sees a single seeding event from a system clock. Using the same seed value as you do will generate the same pseudo random sequence each time.Leatherworker
Could you please explain why you want your pseudo random numbers to be significantly different? Isn't that defeating the purpose of random numbers if you require a deviation - from a statistics point of view you are just as likely to get two numbers close together in sequence as you are far apart (if they are truly random)Northey
H
14

Short answer: Avoid the re-seeding, as it doesn't buy you anything here. Long answer below.


That all depends on what exactly you need. In Common defects in initialization of pseudorandom number generators it is outlined that linear dependent seeds (which 1, 2, 3, 4 definitely are) are a bad choice for initializing multiple PRNGs, at least when used for simulation and desiring uncorrelated results.

If all you do is rolling a few dice, or generating some pseudo-random input for something uncritical, then it very likely doesn't matter.

Note also that using some classes of a PRNG itself for generating seeds have the same problem in generating linear dependent numbers (LCGs spring to mind).

Haruspicy answered 12/10, 2009 at 14:45 Comment(2)
What do you mean by linear dependent seeds? The seeds are one-dimensional, therefore any set of at least two seeds is linear dependent.Fessler
I think they meant that, given a sequence of seeds x_n, the graph { (n, x_n) } of 2d points lies on a line. Namely, the difference between a seed and the following one is constant. Of course, this only makes sense if you order your seeds, although I would imagine that such a set being a bad choice is independent of which seeds come first, i.e. its specific ordering.Outface
R
5

If your random number generator is high quality, it shouldn't matter how you seed it. In fact, the best practice would be to seed it only once. Random number generators are designed to have certain statistical behavior once they're started. Frequently reseeding effectively creates a different random number generator, one that may not be as good.

Randomly selecting seeds sounds like a good idea, but it isn't. In fact, because of the "birthday paradox," there's a surprisingly high probability that you'll pick the same seed twice.

Rationalism answered 12/10, 2009 at 15:48 Comment(0)
C
2

Generally speaking, you only seed your random number generator when you need the random numbers to be generated in identical fashion each time through. This is useful when you have a random component to your processing, but need to test it and therefore want it to be consistent between tests. Otherwise, you let the system seed the generator itself.

In otherwords, by seeding the random number generator with specific pre-defined seeds, you are actually reducing the randomness of the system as a whole. The random numbers generated when using a seed of 1 are indeed psuedo-randomly different from that with a seed of 2, but a hard coded seed will result in repeated random sequences in each run of the program.

Coney answered 12/10, 2009 at 14:45 Comment(0)
V
1

You seem to want pseudo-random numbers that aren't pseudo-random, with a higher probability of consecutive numbers being 'significantly' different than pseudo-randomness requires. I doubt that any common prng will do this, whatever your seeding strategy.

Vaccaro answered 12/10, 2009 at 14:48 Comment(0)
H
0

The seeds themselves should be random so that the output is unpredictable. There can be problems if the seeds differ only in one or two bits (as this question demonstrates).

Hit answered 12/10, 2009 at 14:46 Comment(3)
Manually seeding usually implies that the output doesn't need to be unpredictable. And how much the seeds should differ greatly depends on the algorithm of the PRNG.Haruspicy
It implies the output doesn't need to be unpredictable, but that is also assuming the question asker actually realizes that seeded generators result in the same sequence of numbers.Coney
@Johannes: Absolutely, but if you do truly want unpredictable output then you don't want someone to be able to guess the seed. So for this reason it's best that the seed itself is completely unpredictable (e.g. from /dev/random).Hit
C
0

It depends upon the application for which you're using the PRNG. If you're using something that needs to be cryptographically sound, then the seeds generally need to be extremely difficult to deduce based on the output, different every time the application runs, difficult to simply guess, and impossible to determine by reverse engineering the application (i.e. they can't be hard coded).

If your goal is a game, your requirements may be different. For example, if you're controlling computer strategy, but the computer's strategy remains the same for all runs of the game, you may have an easily beatable game. Then again, you may want that for "easy" mode.

Cofsky answered 12/10, 2009 at 14:47 Comment(1)
If this has anything to do with crypto, then MT19937 is a very wrong generator to begin with, though.Haruspicy

© 2022 - 2024 — McMap. All rights reserved.