Odds of executing something
#1

Is there a better way of doing this:

pawn Код:
if(random(2) == 1)
{
    // 50% chance of code being executed.
}

if(random(3) == 2)
{
    // 33% chance of code being executed.
}

if(random(10) == 2)
{
    // 10% chance of code being executed.
}
Thank you.
Reply
#2

pawn Код:
static randomnumber = random(100);
if(randomnumber <= 50)
{
   // 50%
}
else if(50 < randomnumber <= 83)
{
   // 33%
}
else if(83 < randomnumber <= 93)
{
 // 10%
}
else
{
 // 7%
}
Reply
#3

Here's another way:

pawn Код:
switch(random(5))
{
    case 0: // ...
    case 1: // ...
    case 2: // ...
    case 3: // ...
    case 4: // ...
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)