c - What is the best way to seed srand()? -
this question has answer here:
- recommended way initialize srand? 13 answers
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
Post a Comment