Jump to content
  • Advertisement
Sign in to follow this  
Unconquerable

intresting glitch

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

Hello. I have an intresting problem. In main() i declare two variables.
placex = rand () % 30;
placey = rand() % 10;

As you can see, each variable is set to be random. However, every time i recompile and run the program, the numbers are the same!!What is going on? -Thanks

Share this post


Link to post
Share on other sites
Advertisement
The rand() function isn't really random, you must seed it yourself.. This is done by calling srand() with a number:

srand(10);

for example.. Although, it would be better to seed with a variable value, for example time:

srand(time(NULL));

Share this post


Link to post
Share on other sites
For purposes of testing and simulation it is useful to have a repeatable set of pseudo-random numbers. Therefore, many pseudo-random number generators produce consistant results based on the value you use to seed it.

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!