How can I generate different random numbers at runtime?
I\'ve tried
srand((unsigned) time(0));
But it seems to get me a random numb
srand
is used to seed the random number generator. The 's' stands for 'seed'. It's called "seeding" because you only do it once: once it's "planted", you have a stream from which you can call rand
as many times as you need. Don't call srand
at the beginning of the function that needs random numbers. Call it at the beginning of the program.
Yes, it's a hack. But it's a hack with a very well-documented interface.