Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 ActionScript3.0使用Math.random()_Actionscript 3 - Fatal编程技术网

Actionscript 3 ActionScript3.0使用Math.random()

Actionscript 3 ActionScript3.0使用Math.random(),actionscript-3,Actionscript 3,Actionscript使用Math.random这意味着什么Right=6+Math.random()*2 我懂数学,随机数在0-0.99之间。。。但是它会出来吗(6-7) Math.random()返回一个大于或等于0且小于1.0的数字,即 0Math.random()返回一个大于或等于0且小于1.0的数字,即 0我更喜欢编写一个函数来为您设置刻度和范围。像这样: public static function getRandomNumber(low:Number=0, high:Number

Actionscript使用Math.random这意味着什么Right=6+Math.random()*2

我懂数学,随机数在0-0.99之间。。。但是它会出来吗(6-7)

Math.random()
返回一个大于或等于0且小于1.0的数字,即

0
Math.random()
返回一个大于或等于0且小于1.0的数字,即


0我更喜欢编写一个函数来为您设置刻度和范围。像这样:

public static function getRandomNumber(low:Number=0, high:Number=1):Number
{
    return Math.floor(Math.random() * (1+high-low)) + low;
}
现在你可以称之为:

getRandomNumber(6, 7); //returns 6-7 inclusive

我更喜欢编写一个函数来为您设置比例和范围。像这样:

public static function getRandomNumber(low:Number=0, high:Number=1):Number
{
    return Math.floor(Math.random() * (1+high-low)) + low;
}
现在你可以称之为:

getRandomNumber(6, 7); //returns 6-7 inclusive

我不确定我是否理解你的问题。Math.random*2将是一个介于0和2之间的值。如果你再加上6,你会得到一个6的数字,我不确定我是否理解你的问题。Math.random*2将是一个介于0和2之间的值。如果你再加上6,你会得到一个6的数字