How Does Rand Work With Multiples?

Post Reply
A_Wal_
Corporal - Strongpoint
Corporal - Strongpoint
Posts: 65
Joined: Tue Jul 30, 2019 5:22 pm

How Does Rand Work With Multiples?

Post 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?
pipfromslitherine
Site Admin
Site Admin
Posts: 9700
Joined: Wed Mar 23, 2005 10:35 pm

Re: How Does Rand Work With Multiples?

Post by pipfromslitherine »

They are independent. The second Rand call is only made if the first condition fails.

Cheers

Pip
follow me on Twitter here
A_Wal_
Corporal - Strongpoint
Corporal - Strongpoint
Posts: 65
Joined: Tue Jul 30, 2019 5:22 pm

Re: How Does Rand Work With Multiples?

Post 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.
pipfromslitherine
Site Admin
Site Admin
Posts: 9700
Joined: Wed Mar 23, 2005 10:35 pm

Re: How Does Rand Work With Multiples?

Post 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
follow me on Twitter here
A_Wal_
Corporal - Strongpoint
Corporal - Strongpoint
Posts: 65
Joined: Tue Jul 30, 2019 5:22 pm

Re: How Does Rand Work With Multiples?

Post by A_Wal_ »

Cheers Pip. Not quite sure how it's able to do that but I'll take your word for it. :)
Post Reply

Return to “Sanctus Reach Mods and Scenario Design”