Jump to content
  • Advertisement
Sign in to follow this  
mindspin311

Help with random

This topic is 3901 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

I'm generating the same random terrain every time. I'm using random in cstdlib. I remember using randomize() way back in high school, but can't seem to find it. Is their another way to get different results every run through, or a different package I can use random which includes randomize or a similar function?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by mindspin311
I'm generating the same random terrain every time. I'm using random in cstdlib. I remember using randomize() way back in high school, but can't seem to find it. Is their another way to get different results every run through, or a different package I can use random which includes randomize or a similar function?
You're probably looking for the srand() function (Google will tell you more).

Share this post


Link to post
Share on other sites
You may also want to get a random library because the rand() function in the C standard library is usually a pretty bad pseudo-random number generator.

If you're really into it, you may want to implement your own Mersenne Twister, but that may be overkill.

As jyk said, you probably want srand(). It's a common thing to do to not provide a seed if you're debugging, so that you will get the same numbers every time and tests are predictable. When you want another sequence of pseude-random numbers, you may want to do srand(time(NULL));.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!