Randomness

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
Galbuu
UOX3 Neophyte
Posts: 45
Joined: Mon Jul 05, 2004 9:20 am
Location: Orlando, FL
Has thanked: 0
Been thanked: 0
Contact:

Randomness

Post by Galbuu »

Is there a way to set something up so it chooses a random case? Gah, so hard to find words for it. Here, something like this.

Code: Select all

RandomNumber(1,5);
{
case 1: var vNam = "one";
case 2: var vNam = "two";
case 3: var vNam = "three";
case 4: var vNam = "four";
case 5: var vNam = "five";
}
I really don't want to use ifs because I plan to have a lot of cases.
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

Code: Select all

var randomNum = RollDice( 1, 6, 0 );
var vName = "";
switch( randomNum )
{
case 1: vName = "Batman"; break;

...

case 6: vName = "Dr Freeze"; break;
}
That should do it. RollDice( numberDice, numberFaces, numberToAdd ) is the information you need.
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

You can also use the following to get a random number:

Code: Select all

var randomNum = RandomNumber( 1, 6 );
-= Ho Eyo He Hum =-
Post Reply