Created
September 19, 2013 13:57
-
-
Save funrep/6623879 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// tror denna ska funka, kan ej C++ xD | |
int randR(unsigned int min, unsigned int max) { | |
int x = rand(); | |
if (RAND_MAX == x) return randR(min, max); | |
int range = max - min, | |
remainder = RAND_MAX % range, | |
bucket = RAND_MAX / range; | |
if (x < RAND_MAX - remainder) { | |
return min + x/bucket; | |
} else { | |
return randR (min, max); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment