Skip to content
Snippets Groups Projects
Commit fabb6073 authored by Théo Le Calvar's avatar Théo Le Calvar
Browse files

fix nextInt / nextBool crash

parent e7957911
Branches
No related tags found
No related merge requests found
...@@ -4,39 +4,18 @@ ...@@ -4,39 +4,18 @@
unsigned long int Random::random(void) unsigned long int Random::random(void)
{ {
static unsigned long int random_seed = 93186752; static unsigned long int random_seed = 93186752;
static unsigned int a = 1588635695, q = 2, r = 1117695901; static unsigned long int a = 1588635695, q = 2, r = 1117695901;
random_seed = a*(random_seed % q) - r*(random_seed / q); random_seed = a*(random_seed % q) - r*(random_seed / q);
return random_seed; return random_seed;
}; };
int Random::nextInt(int max){ int Random::nextInt(int max) {
return random() % max;
long double base;
long double i;
int resultat;
base = (long double)random();
i = (base / RAND_MAX);
i = i*max;
resultat = 0;
while ((resultat < i) && (resultat < max)) {
resultat++;
}
return resultat;
}; };
bool Random::nextBool(){ bool Random::nextBool(){
return random() & 1;
unsigned long int base;
float i;
base = random();
i = base / RAND_MAX;
if(i<(0.5)) return 1; else return 0;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment