Odds of executing something - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Odds of executing something (
/showthread.php?tid=565233)
Odds of executing something -
Whizion - 26.02.2015
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.
Re: Odds of executing something -
rickisme - 26.02.2015
pawn Код:
static randomnumber = random(100);
if(randomnumber <= 50)
{
// 50%
}
else if(50 < randomnumber <= 83)
{
// 33%
}
else if(83 < randomnumber <= 93)
{
// 10%
}
else
{
// 7%
}
Re: Odds of executing something -
SickAttack - 26.02.2015
Here's another way:
pawn Код:
switch(random(5))
{
case 0: // ...
case 1: // ...
case 2: // ...
case 3: // ...
case 4: // ...
}