shamuraq Posted May 19, 2009 Share Posted May 19, 2009 [scenario] I'm randomising 4 variables as such: <? $a = rand(1,9); $b = rand(1,9); $c = rand(1,9); $d = rand(1,9); echo "$a * $b = $c * $d; ?> [Question] How do i make sure $a * $b = $c * $d, and no decimal? Thanx in advance.... Quote Link to comment https://forums.phpfreaks.com/topic/158704-logical-randomising-ii/ Share on other sites More sharing options...
Daniel0 Posted May 19, 2009 Share Posted May 19, 2009 do { $a = rand(1,9); $b = rand(1,9); $c = rand(1,9); $d = rand(1,9); } while ($a * $b != $c * $d); Quote Link to comment https://forums.phpfreaks.com/topic/158704-logical-randomising-ii/#findComment-836970 Share on other sites More sharing options...
sasa Posted May 19, 2009 Share Posted May 19, 2009 or <?php $a = rand(1,9); $b = rand(1,9); $x = $a * $b; $arr = array(); for ($i = 1; $i <= sqrt($x); $i++) if (($x % $i == 0) and $x / $i < 10) $arr[] = $i; $c = $arr[rand(0, count($arr)-1)]; $d = $x / $c; echo "$a, $b; $c, $d"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/158704-logical-randomising-ii/#findComment-837041 Share on other sites More sharing options...
shamuraq Posted May 19, 2009 Author Share Posted May 19, 2009 thanx guys.... Quote Link to comment https://forums.phpfreaks.com/topic/158704-logical-randomising-ii/#findComment-837406 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.