Jump to content
  • Advertisement

Archived

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

Estauns

Randomizing Floats?

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

How would you go about randomizing floats? So you could say get back between 0.0 - 1.0 any number (within a certain degree) between the two?

Share this post


Link to post
Share on other sites
Advertisement
float result = (float)rand()/(float)RAND_MAX;

rand() returns a number between 0 and RAND_MAX, so this should give you a 0.0f to 1.0f range.

Share this post


Link to post
Share on other sites
Or use some code like the Mersenne Twister that will give you 0.0f to 0.9999999999f and do it faster than the rand statement can give you an integer.

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.

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!