AS3 randRange() functionA

AS3 randRange() function

Recently I needed to generate a random number of items for a unit test in flex. In ColdFusion this is easy, I can use the randRange(x,x) function. However, there is not a randrange() function built into AS3.

So with a little help from google, here is a simple AS3 randRange() you can use.

[Update: Thanks to Till & Keith, here is an updated function]

function randRange(start:Number, end:Number) : Number
{
return Math.floor(start +(Math.random() * (end - start)));
}

Share

0 条评论

留下评论