c - What is the best way to seed srand()? -


this question has answer here:

the way learned seed random number generator srand(time(null)) , use calls rand() generate random numbers. problem approach if run program multiple times in same second, random numbers generated same. way around this?

on posix systems, use clock_gettime current time in nanoseconds. if don't need lot of bits, can forget prng , use low-order bits of time random number directly. :-)


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -