0

Hey,

Does anybody know of a way to generate a random number without using srand(time(NULL)). I need it for a program I'm writing.

srand(time(NULL)) is seeding it based on the computer's clock, but it's only accurate to the nearest second, so it's not fast enough. I've had to put Sleep(1000) in front of it, so it will generate a different number instead of the same one. The Sleep() makes my program (a VMF generator) run VERY slowly.....

vs49688

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by firstPerson
0

Hey,

Does anybody know of a way to generate a random number without using srand(time(NULL)). I need it for a program I'm writing.

srand(time(NULL)) is seeding it based on the computer's clock, but it's only accurate to the nearest second, so it's not fast enough. I've had to put Sleep(1000) in front of it, so it will generate a different number instead of the same one. The Sleep() makes my program (a VMF generator) run VERY slowly.....

vs49688

You only call srand once, at the beginning of your program, not for every number you pick. Call srand once, then call rand () for each number after that, so if you are generating ten numbers, you call srand (time (0)) once, then rand () ten times.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.