ServUO Version
Publish 57
Ultima Expansion
Endless Journey
Exactly as the title says, I've bee digging through scripts and posts to try and find an answer but haven't come across anything, or I don't know what I'm looking for. Anyways I need a piece of code that will pick randomly 1 of 2 numbers, the numbers themselves won't change and I don't need anything between them, just 1 of the 2 numbers needs to be chosen. I'm sure someone smarter than me will know it immediately :)
 
Utility.RandomList(5, 8);
It can also keep going if wanted and also works for many other things doesn't just have to be an int:

Utility.RandomList(2, 4, 6, 8, 10, 12);

Utility.RandomList(typeof(Dragon), typeof(Drake), typeof(Wyvern))
 
Well there are ultimately more ways than one.

Variant 1:
C#:
int number = 10;
if(Utility.RandomBool())
    number = 20;

Variant 2:
C#:
int number = Utility.RandomList<int>(10, 20);

Variant 3:
C#:
int[] array = new int[] { 10, 20 };
int number = array[Utility.Random(array.Length)];

Variant 4:
C#:
int number = 10;
if (Utility.RandomDouble() > 0.5)
    number = 20;

and so on
 
Back