Change probability calculation trunk
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 22 Jan 2025 12:38:00 +0000 (13:38 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 22 Jan 2025 12:38:00 +0000 (13:38 +0100)
Instead of using lower/higher halves of the return range use modulo 2.
This is easier to generalize.

ex03/RobotomyRequestForm.cpp

index 763156b23f15232ead9ca4e0c57162ca51b2fd06..c217ff5ee86d2cae3eae63e5ceb74545c886f752 100644 (file)
@@ -40,7 +40,7 @@ bool  RobotomyRequestForm::getRandomBit()
                std::srand(std::time(0));
                is_seeded = 1;
        }
                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
 }
 
 RobotomyRequestForm    *RobotomyRequestForm::createNew(const std::string &target) const