Don’t use srand(clock()), use srand((unsigned)time(NULL)) instead

By Stephen Kellett
9 July, 2010

Typically you use srand() when you need to start the random number generator in a random place. You may do this because you are going to generate some keys or coupons and want them to start in an unpredictable place.

From time to time we provide special offers to customers in the form of a unique coupon code that can be used at purchase to get a specific discount. These coupons are also used to provide discounts to customers upgrading from say Performance Validator to rdtsc() to get the CPU timestamp and cast the result to seed srand().
rdtsc() is unlikely to return duplicate values as it returns the number of instructions executed by the processor since startup.

Fully functional, free for 30 days