Member Avatar

vs49688

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

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.