SA-MP Forums Archive
Random events - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random events (/showthread.php?tid=79130)



Random events - lol2112 - 25.05.2009

Hi,
I have a question about randomising events. I've read the wiki and I know how to randomise, I'm just not sure about applying it. I can see how it works when each event has an equal probability of occurring, e.g.

Код:
new a = random(1);
if(a == 0)
{
    Do something
}
else if(a == 1)
{
   Do something else
}
here the probability for either event is equal (1/2), but it could be a 1/3 each or 1/4 each, etc...

What I don't get how to do is have different probabilities for the events occurring, e.g.

Код:
new a = random(9)
if(a <= 2)
{
    Do something
}
else if(a > 2 && a <= 5)
{
    Do something else
}
else if(a > 6 && a <= 9)
{
    Do NOTHING
}
Here the probability of something happening appears to be 6/10, and the probability of nothing happening appears to be 4/10. I'm not very good with probability, I can't usually get my head round it, but my way of seeing it is that the probabilities aren't what I said. Surely having something happening at one extreme and nothing at the other extreme would have an effect on the true probabilities? Would it not be better to have the event NOTHING happening on a = 0, 3, 6, 9 (still 4/10 but not at extremes) and the event SOMETHING happening on a = 1, 2, 4, 5, 7, 8 (still 6/10)?

Is there a better and fairer way of doing random events than this? Or am I completely wrong about random() being biased?

Many thanks.


Re: Random events - Backwardsman97 - 28.05.2009

I don't get what you mean. You want to do what now? Like this?

pawn Код:
new a = random(9);
switch(a)
{
   case 0,3,6,0:
   {
     //Do nothing
   }
   case 1,2,4,5,7:
   {
     //Do something
   }
}



Re: Random events - lol2112 - 28.05.2009

Woah a reply! That's pretty much what I want to do yeah. I didn't think of using a switch...that makes it a whole lot easier. Thanks!