Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.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
Javascript 如何在两组数字之间设置math.random_Javascript - Fatal编程技术网

Javascript 如何在两组数字之间设置math.random

Javascript 如何在两组数字之间设置math.random,javascript,Javascript,我试图在一组数字之间设置一个Math.random值的尝试失败了很多次,并且不知道如何执行 我之前尝试过的是设置math.floor(math.random()*400)-200;看看函数是否会得到一个介于400和200之间的数字 Math.floor(Math.random() * 400) - 200; 但是函数最终得到给定的数字并减去200,我想你需要Math.random()*200+200我想你想要Math.random()*200+200试试Math.floor((Math.ran

我试图在一组数字之间设置一个Math.random值的尝试失败了很多次,并且不知道如何执行

我之前尝试过的是设置math.floor(math.random()*400)-200;看看函数是否会得到一个介于400和200之间的数字

Math.floor(Math.random() * 400) - 200;

但是函数最终得到给定的数字并减去200,我想你需要
Math.random()*200+200

我想你想要
Math.random()*200+200

试试Math.floor((Math.random()+1)*200)

试试数学地板((Math.random()+1)*200)

您可以使用
Math.floor(Math.random()*200)+200它生成一个数字btw 0-200,和其他200求和,得到200-400之间的数字,你可以使用
Math.floor(Math.random()*200)+200它生成一个数字btw 0-200,并将其他200相加,得到200-400之间的数字