Skip to content

Instantly share code, notes, and snippets.

@funrep
Created September 19, 2013 13:57
Show Gist options
  • Save funrep/6623879 to your computer and use it in GitHub Desktop.
Save funrep/6623879 to your computer and use it in GitHub Desktop.
// 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