From: Lukas Jiriste Date: Wed, 22 Jan 2025 12:38:00 +0000 (+0100) Subject: Change probability calculation X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=248f0e73718b7f2d192f019b809a547fa2ceb933;p=42%2FCPP_Module_05 Change probability calculation Instead of using lower/higher halves of the return range use modulo 2. This is easier to generalize. --- diff --git a/ex03/RobotomyRequestForm.cpp b/ex03/RobotomyRequestForm.cpp index 763156b..c217ff5 100644 --- a/ex03/RobotomyRequestForm.cpp +++ b/ex03/RobotomyRequestForm.cpp @@ -40,7 +40,7 @@ bool RobotomyRequestForm::getRandomBit() std::srand(std::time(0)); is_seeded = 1; } - return (std::rand() > (RAND_MAX / 2)); + return (std::rand() % 2); } RobotomyRequestForm *RobotomyRequestForm::createNew(const std::string &target) const