Random Number Generator

March 1, 2010 |  by  |  Project Three, Tutorials

I wanted to get something to play at a random delay time, so I found a function to generate a random number:

//To call the function, define lowest, and highest numbers you want to get (in this case it will return a random number between 1, and 5)

randomNumber(1, 5)

//Random Number Generator
function randomNumber(low:Number=NaN, high:Number=NaN):Number
var low:Number = low;
var high:Number = high;

throw new Error(“low must be defined”);
throw new Error(“high must be defined”);
return Math.round(Math.random() * (1+high – low)) + low;}

1 Comment

  1. Can you share exactly how you used this in your fla? The stand alone code may not make much sense to others.