0

Random numbers

Can someone explain this code to me? It's in one of the quizzes that it outputs 2,8,24... but NOT 6 <?php $random = rand(1,3); $result = 24/$random; echo $result; ?>

22nd Jul 2019, 12:03 PM
Jesse Brite
Jesse Brite - avatar
3 Respostas
+ 1
It is because rand function in the example generates random numbers between 1 and 3 (including 3). So the maximum number in $random variable is 3 => 24/3 = 8. It's not 6 because the upper limit in rand function is 3 not 4. You can find more info about rand function here:https://www.php.net/manual/en/function.rand.php. Hope it helps you 😉
22nd Jul 2019, 12:39 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Thanks a lot @TheWhiteCat
22nd Jul 2019, 1:18 PM
Jesse Brite
Jesse Brite - avatar
0
You are welcome Jesse Brite 😉
22nd Jul 2019, 4:38 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar