Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What (else) is wrong with using time as a seed for random number generation?

I understand that time is an insecure seed for random number generation because it effectively reduces the size of the seed space.

But say I don't care about security. For example, say I'm doing a Monte Carlo simulation for a card game. I DO however, care about getting as close to true randomness as possible. Will time as a seed affect the randomness of my output? I would think the choice of PRNG matters more than the seed in this case.

like image 863
pepsi Avatar asked Jul 12 '11 19:07

pepsi


People also ask

What would happen if the same seed value is used each time a random object is created?

If the same "seed" value is specified, the sequence of psuedo-random numbers will be the same. This example shows the generation of 2 sets of 8 random integer numbers from 0 to 34 inclusive, where the random seed is set at 55 for both sets.

What is the point of using a seed when generating random number?

The purpose of the seed is to allow the user to "lock" the pseudo-random number generator, to allow replicable analysis. Some analysts like to set the seed using a true random-number generator (TRNG) which uses hardware inputs to generate an initial seed number, and then report this as a locked number.

Why is it important to set the random seed at the beginning of a simulation?

A seed is used to set the starting point for generating a series of random numbers. The seed sets the generator to a random starting point. A unique seed returns a unique random number sequence. This might be of help .


2 Answers

For security purposes you obviously need a high entropy seed. And time alone cannot provide that.

For simulation purposes the quality of the seed doesn't matter much, as long as it's unique. As you noted the quality of the PRNG is more important here.
Even a PRNG in a game may need to be secure. For example in multiplayer games a player might find out the internal state of the PRNG and use that to predict future random events, guess the opponent cards, get better loot,...

One common pitfall using time to seed a PRNG is that the time doesn't change very often. For example on windows most time related functions only change their return value every few milliseconds. So all PRNGs created withing that interval will return the same sequence.

like image 135
CodesInChaos Avatar answered Oct 19 '22 08:10

CodesInChaos


Just for the sake of completeness, this paper by Matsumoto et al. nicely illustrates how important the initialization scheme (ie. the way of choosing your seed(s)) is for simulation. Turns out a bad initialization scheme may strongly bias the results, even though the RNG algorithm as such is rather good in principle.

like image 34
Roland Ewald Avatar answered Oct 19 '22 07:10

Roland Ewald