# Help on Random functions

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

## 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 on other sites
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 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 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.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013157
×