Mail Archives: djgpp/1999/09/26/11:01:11
> Can you suggest what to use instead?
No, I reckon time() is fine. Remember that DJGPP and most other compilers of
most other languages get random numbers from a list of random numbers, you are
just roughly setting the list entry point (it might do something like use your
seed to lookup a table entry and use that entry to use a start position - I
don't think the behaviour is strictly defined).
So, your program will give entirely different results for its entire run for
every unique second of the day it starts on. If your program is being started
more than once a second, you might consider doing something like reading the
time and getting the t-state timer value if your CPU supports it (pentium and
above) to combine. XORs are always good for that sort of thing.
Other sources of random numbers might be to search your hard disk until you
find the first file (starting in a temp directory would be good) and read some
bytes from that, or create a pointer and read from it without allocating
memory to it (whatever you do, don't write to it though!). The possibilities
are literally endless.
Another good idea might be for your program to read a random value on exit
and save it to load the next time it starts as a random seed. That would
probably be quite unpredictable, especially if the number of times you get
random numbers varies from execution to execution. The Linux kernel does
something similar to this.
-Thomas
- Raw text -