Monkuar Posted May 29, 2013 Share Posted May 29, 2013 $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? 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. 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
Archived
This topic is now archived and is closed to further replies.