Monkuar Posted May 29, 2013 Share Posted May 29, 2013 (edited) $roll = rand(1, 100); $failureChance = 100 - $successrate; if ($roll > $failureChance) { // This is successful. } VS: $rand = mt_rand(1, 100); if ($rand > $successrate) // Success rate is your integer; 87 for 87% for example { // This is a failure. } Are they both essentially the same? Why the heck is that guy using the $falureChance variable? (Cite from http://www.codingforums.com/showthread.php?t=250281) Edit: also, which one is more professional/correct way? Edited May 29, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/278552-difference-between-these-2-percent-calculations-lol/ Share on other sites More sharing options...
kicken Posted May 29, 2013 Share Posted May 29, 2013 Are they both essentially the same?Yes. Why the heck is that guy using the $falureChance variable? Because the other guy was having a hard time understanding the inverted logic of the other code, so he tried to make it easier to understand by renaming the variable. Quote Link to comment https://forums.phpfreaks.com/topic/278552-difference-between-these-2-percent-calculations-lol/#findComment-1433019 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.