Skip to content

Instantly share code, notes, and snippets.

@remirobert
Last active August 29, 2015 14:01
Show Gist options
  • Save remirobert/028b3c28720dbe241f0a to your computer and use it in GitHub Desktop.
Save remirobert/028b3c28720dbe241f0a to your computer and use it in GitHub Desktop.
float random
//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