Search code examples
securityrandomsimulationmontecarloprng

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.


Solution

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