A
AngleWyrm
Ok, I know that srand( time(NULL) ) isn't such a good idea, but I do it
anyway. Why? The clock is an easy source of randomness. And I've got this
sneaky suspicion that I'm not the first guy to commit this foul atrocity
against the finer design principles of RNGs in general...
So here's me thought: Design a seeding function that has only one purpose --
and that purpose is to use time(NULL) as it's input, and generate a
reasonably random output for seeding a random number generator.
As of right now, the value of time(NULL) on my machine is: 1095397643 (1.095
billion), and increments once per second. the return value is of time_t,
which according to www.cplusplus.com is generally defined as a long. It's
four bytes on my machine.
USAGE...here's where things differ markedly from "normal" RNGs:
It occurs to me that this function doesn't really have to return a different
series ten thousand years from now. Most people are going to use it in rapid
succession several times over the course of an hour or three -- usually the
same hour or three in a day. Even more to the point, RAND_MAX is usually
defined as 32768, or 2^15.
Thus what we have here is a function that maps a spread of numbers from one
domain to another, and we are reasonably sure the domain to map to is the
2^15 random numbers in the range [0..32768).
Now another thing to notice: We don't need thirty two thousand random seeds.
Most of the time, only the first number is used, and far less often the
first dozen or hundred.
How then can I approach the problem of selecting just one random number
given a sequential seed? It occurs to me to perhaps use some standard number
sequence, maybe offset or modified?
anyway. Why? The clock is an easy source of randomness. And I've got this
sneaky suspicion that I'm not the first guy to commit this foul atrocity
against the finer design principles of RNGs in general...
So here's me thought: Design a seeding function that has only one purpose --
and that purpose is to use time(NULL) as it's input, and generate a
reasonably random output for seeding a random number generator.
As of right now, the value of time(NULL) on my machine is: 1095397643 (1.095
billion), and increments once per second. the return value is of time_t,
which according to www.cplusplus.com is generally defined as a long. It's
four bytes on my machine.
USAGE...here's where things differ markedly from "normal" RNGs:
It occurs to me that this function doesn't really have to return a different
series ten thousand years from now. Most people are going to use it in rapid
succession several times over the course of an hour or three -- usually the
same hour or three in a day. Even more to the point, RAND_MAX is usually
defined as 32768, or 2^15.
Thus what we have here is a function that maps a spread of numbers from one
domain to another, and we are reasonably sure the domain to map to is the
2^15 random numbers in the range [0..32768).
Now another thing to notice: We don't need thirty two thousand random seeds.
Most of the time, only the first number is used, and far less often the
first dozen or hundred.
How then can I approach the problem of selecting just one random number
given a sequential seed? It occurs to me to perhaps use some standard number
sequence, maybe offset or modified?