Create random numbers within a range?
What's a sim开发者_如何学Pythonple way to generate random numbers with a range?
Will this work?
private function randRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
use Math.random function that return n such as 0.0 <= n < 1.0
so this one return n such as min<= n< max
function random(min:Number, max:Number):Number {
return Math.random()*(max-min)+min;
}
if you want to include the max range look at this one
精彩评论