Last active
August 29, 2015 14:01
-
-
Save remirobert/028b3c28720dbe241f0a to your computer and use it in GitHub Desktop.
float random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This will generate a number from 0.0 to 1.0, inclusive. | |
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); | |
//This will generate a number from 0.0 to some arbitrary float, X: | |
float r2 = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/X)); | |
//This will generate a number from some arbitrary LO to some arbitrary HI: | |
float r3 = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO); | |
// from http://stackoverflow.com/questions/686353/c-random-float-number-generation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment