1. The rand function never generates "random" numbers. It generates pseudo random numbers (feel the difference

). There is a very interesting (and complex) mathematical theory on pseudo random sequences. See, for example:
http://en.wikipedia.org/wiki/Random_number_generator
Apropos: it's not so easy to generate "true" random numbers on such deterministic device as a digital computer

...
2. Use
srand(time(0)) call to initiate different pseudorandom sequences.
3. Never use the rand library function in serious applications. Nobody knows why but all known programming language implementations have a very bad pseudorandom generators

. There are some good pseudorandom generators. One of the best is so called Mersenne Twister. There are lots of its freeware C and C++ implementations. See, for example:
http://www.bedaux.net/mtrand/ Last edited by ArkM; Mar 27th, 2009 at 7:07 pm.
Reputation Points: 1234
Solved Threads: 347
Postaholic
Offline 2,001 posts
since Jul 2008