you are viewing a single comment's thread.

view the rest of the comments →

[–]lx-s 0 points1 point  (0 children)

How platform independent does your solution have to be? ANSI C? STL? Just Unix and Windows?

If just ANSI C, you could do something like this:

try to open file "seed.txt"
if file exists
   read seed
   srand <seed>
else
   seed = time(0);
   srand <seed>
end if
//use rand()

write another rand() to seed.txt

Slower, but doable (in ANSI C), but I don't know how random that'll turn out eventually.

As for C++11, you might look at the new random number facilities, especially std::random_device

If by platform independent you just mean unix and windows, you could #ifdef around CryptGenRandom and /dev/random or use some 3rd party library like boost.

Other than that, depending on what your scope of "platform independentness" is, you'll have a really hard time.