Page 1 of 1

How Does Rand Work With Multiples?

Posted: Fri Mar 06, 2020 2:33 pm
by A_Wal_
if (Rand(1,100) > 50)
{
}
else if (Rand(1,100) < 31)
{
}

Does this give a 15% chance of the second condition being met or 30%?
In other words, do the Rands overlap?

Re: How Does Rand Work With Multiples?

Posted: Fri Mar 06, 2020 10:07 pm
by pipfromslitherine
They are independent. The second Rand call is only made if the first condition fails.

Cheers

Pip

Re: How Does Rand Work With Multiples?

Posted: Sat Mar 07, 2020 12:28 am
by A_Wal_
Cheers Pip.

Just to clarify, you're saying a 15% chance in the first example?
Because in the scripting I did a few years ago the way randoms worked was on the clock so because both Rands are in the same frame it will give the same random number if you have two Rands. After all, there's no such thing as truly random, it must be returning a predetermined result somehow.

So you're saying that this...

if (Rand(1,100) > 50)
{
if (Rand(1,100) > 50)
{
}
}

...gives a 25% chance of the 2nd condition being met?

Sorry, just want to be sure I understand.

Re: How Does Rand Work With Multiples?

Posted: Mon Mar 09, 2020 2:46 pm
by pipfromslitherine
Each call to Rand will return a different result (to any degree of accuracy - in theory of course a random number generator COULD return the same result time after time... :) ). It uses a pseudo-random generator very similar to the standard C algorithm. So yes, 15% chance to trigger the second condition.

Cheers

Pip

Re: How Does Rand Work With Multiples?

Posted: Tue Mar 10, 2020 12:39 pm
by A_Wal_
Cheers Pip. Not quite sure how it's able to do that but I'll take your word for it. :)