Jump to content

Difference Between These 2 Percent Calculations lol


Monkuar

Recommended Posts

$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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.