Random events
#1

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.
Reply
#2

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
   }
}
Reply
#3

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)