Jump to content
  • Advertisement
Sign in to follow this  
neilski_2003

Help on Random functions

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

Could anyone help, or point me in the direction of some for random functions please. I'm doing an asteroids environment and i wish to generate them randomly within the environement. I would also like to have them rotate about a random axis. Cheers in advance. Neil

Share this post


Link to post
Share on other sites
Advertisement
If you are looking for a function to generate random values, there is srand() and rand().

srand seeds the random number generator with a value (such as the current time) and rand returns a random number within the range 0 and RAND_MAX.

Share this post


Link to post
Share on other sites
Sorry i'm relatively new to this game so could you give me an example of how i'd use the srand() function.

The idea is that i've got an asteroid and i'd like to set it so that a random translation is put on them so they appear at random places in the world.

Once i've done that i also hope to nest in some random rotation but i'll need to understand the format of how random works before i could do that.

Cheers again
Neil

Share this post


Link to post
Share on other sites
srand() uses a "seed" to generate more random numbers. Before you start generating random numbers, it's a good idea to srand(time(0)). This takes the current time as a seed, thus, making a more random number. Then the value rand()%(n) will generate a number between 0 and n.

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!