HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

If current time in milliseconds is considered good enough random seed for a pseudorandom number generator, why not just use that time directly?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
randomwhymillisecondsnumberjustconsideredtimegeneratorseedthat

Problem

I was reading about pseudorandom number generators and how they need a seed and how that seed is usually current system time in milliseconds. One of the most common algorithms is the linear congruential generator, which is an algorithm that based on some fixed constants and this seed through some mathematical computations gives the final pseudorandom output.

But what are the disadvantages of using this time directly as a pseudorandom number?

Solution

The key property that we want from (non-cryptographic) pseudorandom numbers is that they "look" independent. In particular, say you have some algorithm that requires a PRNG to perform well and you give it a current time function as a PRNG. Then, if the algorithm repeatedly queries what is supposed to be a PRNG, it will actually see that it gets the same value many times in a row until, until it eventually increments by one. These values are very, very far from random and can be detrimental to algorithmic performance.

Context

StackExchange Computer Science Q#116139, answer score: 4

Revisions (0)

No revisions yet.