From dc357eae204c01327c81fd6e48589ec9b0bc8641 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Le=20Calvar?= <theo.le-calvar@imt-atlantique.fr>
Date: Fri, 24 Feb 2023 16:10:02 +0100
Subject: [PATCH] fix nextInt / nextBool crash

---
 Applications/SuperPong/random.cpp | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)

diff --git a/Applications/SuperPong/random.cpp b/Applications/SuperPong/random.cpp
index c962914..3a37cae 100644
--- a/Applications/SuperPong/random.cpp
+++ b/Applications/SuperPong/random.cpp
@@ -4,39 +4,18 @@
 
 unsigned long int Random::random(void)
 {
-
    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);
    return random_seed;
 };
 
 
-int Random::nextInt(int 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;
+int Random::nextInt(int max) {
+	return random() % max;
 };
     
 bool Random::nextBool(){
-
-unsigned long int base;
- float i;
-
-	base = random();
-	i = base / RAND_MAX;
-	if(i<(0.5)) return 1; else return 0;
+	return random() & 1;
 };
-- 
GitLab