Skip to main content
gamedev.net
🔒 Locked

Randomizing

Started by Grat Jan 16, 2002 at 8:44 AM 0 replies 450+ views
Original Post
Grat
Grat
Ive got a problem in my c++ game, with randomizing. basically i seed the randomizer with the time, like this: srand( time ( NULL ) ); This is inside a class function, which is called every game loop. However, it doesnt make the number quite random, because it is clear that the number is slowly going up every game loop. Is there any way to make the number more randomized?
Doener
Doener
The problem is that you call srand() every time. You should call it only once the program starts. Then every time you retrieve a random number with rand() this number should be quite random. if you don''t trust the number generator that much you could add simply events that call srand() with some value, but a) keep it very simple or else it will slow your code down and b) that won''t make the numbers much more random, calling srand() once is as good.
The only other way is to find a generator that you trust, or write one yourself ;-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.