RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

RandomList help

Barnicoat

Sorceror
Hi all,

I'm just looking for some clarification on how RandomList would work in the context below. The information and examples I've found on the forums and internet don't fully explain it (at least the way I read it.)

The following code determines the chance of a particular hue Cu Sidhe spawning.

Code:
 double chance = Utility.RandomDouble() * 23301;
 
if ( chance <= 1 )
Hue = 0x489;
else if ( chance < 50 )
Hue = Utility.RandomList( 0x657, 0x515, 0x4B1, 0x481, 0x482, 0x455 );
else if ( chance < 500 )
Hue = Utility.RandomList( 0x97A, 0x978, 0x901, 0x8AC, 0x5A7, 0x527 );

Take this part for example:

else if ( chance < 50 )
Hue = Utility.RandomList( 0x657, 0x515, 0x4B1, 0x481, 0x482, 0x455 );

If chance is less than 50 (but greater than 1), then ONE of the following hues will be assigned to that mobile. Or does EACH of the hues listed have a 1 in 50 chance.

With the total weight being 23301, the chance of getting a normal coloured cu is either ~86% or ~98%, depending on the sentence above... which is a big difference ;)

Hopefully I've explained my question clearly enough.

Any help would be great.

EDIT: I found a couple threads relating to randomlist, even one about cu colours.

A statement by Vorspire in 2008,

"Each time you make a call to the RandomList function, it will return a different value."

That seems to imply that is chance is greater than 1 and less than 50, that ONE of the hues listed will be assigned to the mob. Meaning that the colours are a lot rarer than if they all had a 1 in 50 chance.
 

daat99

Moderator
Staff member
Code:
double chance = Utility.RandomDouble() * 23301;

The "RandomDouble" function returns a number between 0.0 and 0.999...999.

You multiply it by 23301 and you get a number between 0.0 and 23300.999...999 (including 0 but not 23301).

The "if (x<chance)" part checks the value against the number we got.

Basically you have:
1/23301 chance to get the first if statement.
(50-1)/23301 chance to get the second if statement.
(500-50)/23301 chance to get the third if statement.
(23301-500)/23301 chance to get the last else statement (normal hue)

Once you got the second or third if statements you still have a 1/6 chance to get one of the colors.
So basically you have:
1/23301 chance to get hue 0x489
((50-1)/23301)/6 chance to get each hue in the second list
((500-50)/23301)/6 chance to get each hue in the third list
(23301-500)/23301 chance to get the default hue

That means that in 98% of the time you'll get default hued Cu Sydhe.
 

Barnicoat

Sorceror
Thank you Sir! That's basically what I got from it too. But I'm only learning, so it's very good to have someone confirm it :)
 
Top