【问题标题】:How to set math.random in between sets of numbers如何在数组之间设置 math.random
【发布时间】:2019-06-10 05:16:41
【问题描述】:

我在一组数字之间设置 Math.random 值的尝试多次失败,并且不知道如何执行此操作。

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

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

但函数最终将给定的数字减去 200

【问题讨论】:

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

标签: javascript


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      相关资源
      最近更新 更多