Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Grat

Randomizing

This topic is 6000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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 ;-)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!