开发者

Create random numbers within a range?

开发者 https://www.devze.com 2023-02-08 09:04 出处:网络
What\'s a sim开发者_如何学Pythonple way to generate random numbers with a range?Will this work?

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

精彩评论

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