GARTHWILSON wrote:
the fact that you normally have no idea what its value will be when it gets read means that it can be used for a truly random factor in coming up with the seed.
.
.
I should have put this in my "Tip of the Day" column four years ago in what now is the Delphi forum archives at
http://www.6502.org/forum/viewtopic.php?t=342
That definitely deserves some caveats
You have to keep in mind that the randomness comes from
the timing, not the timer.
eg you wouldn't want to seed from the timer as part of an
initialization at power on, you might as well use a constant.
But choice and use of some external event takes some care too.
IF you've carefully constructed you're PRNG with a long
sequence of which you will use only a small part,
you're not going to want to settle for a 16 bit value as
the seed just cause that's the length of the timer, you would
have just thrown away most of your PRNGs "randomness"
If your PRNG uses 32 bit values, a 32 bit timer might help,
but if you eg seed from timing of the first keystroke
after power on, and that usually comes in a relatively small
range of values, it might not help much.
ie if your timer takes 8 seconds to cycle through the possible
seeds but you usually hit the first key within 1-3 seconds
you might not be much better off.
If you were simulating the flip of a coin, you might be ok,
but if you're trying to do monte carlo, calculations maybe not.
The lower bits of the timer might look a lot more random
than the higher bits. If you were simulating the flip of a
coin, the lowest bit of the timer might be good enough by
its self (forget the PRNG).
If you're seeding you're PRNG by timing keystrokes you
could be better off composing a 32 bit seed from two 16 bit
timer values, as opposed to a single 32 bit timer value,
but you might be a LOT better off using four eight bit
values (from the lower eight timer bits)