Flash AS3: Random Low/High

//call this function, pass it two numbers (low number, high number)
// should return a random number between lo and high number
// some error checking,  checks to see if low number < high number

function randomNumber(low:Number=NaN, high:Number=NaN):Number {

var low:Number=low;
var high:Number=high;

if (isNaN(low)) {
throw new Error(“low must be defined”);

if (isNaN(high)) {
throw new Error(“high must be defined”);

if (low>high) {
throw new Error(“low number must be less then high number”);

return Math.round(Math.random() * (high – low)) + low;


This post is tagged: , ,

Comments are closed.