开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜