How Does Rand Work With Multiples?

Post Reply
A_Wal_
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Tue Jul 30, 2019 5:22 pm

How Does Rand Work With Multiples?

Post by A_Wal_ » Fri Mar 06, 2020 2:33 pm

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: 9252
Joined: Wed Mar 23, 2005 10:35 pm

Re: How Does Rand Work With Multiples?

Post by pipfromslitherine » Fri Mar 06, 2020 10:07 pm

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

Cheers

Pip
follow me on Twitter here

A_Wal_
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Tue Jul 30, 2019 5:22 pm

Re: How Does Rand Work With Multiples?

Post by A_Wal_ » Sat Mar 07, 2020 12:28 am

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: 9252
Joined: Wed Mar 23, 2005 10:35 pm

Re: How Does Rand Work With Multiples?

Post by pipfromslitherine » Mon Mar 09, 2020 2:46 pm

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_
Lance Corporal - SdKfz 222
Lance Corporal - SdKfz 222
Posts: 26
Joined: Tue Jul 30, 2019 5:22 pm

Re: How Does Rand Work With Multiples?

Post by A_Wal_ » Tue Mar 10, 2020 12:39 pm

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”