如何在JavaScript中实现Random.nextDouble()?

时间:2018-09-24 11:21:24

标签: javascript random

我正在使用Math.floor((Math.random()* max-min)+ min)生成随机数, 此函数和random.nextDouble()有什么区别? 如何在Javascript中实现random.nextDouble?

1 个答案:

答案 0 :(得分:0)

1。

var min = 99; var max = 101; Math.floor(Math.random() * (max - min)) + min; //random int from min to max (not including)
  1. int(32位)[-2 ^(32-1),+ 2 ^(32-1)+1]([-2147483648,2147483647]);

  2. 双精度(64位)[-4.9e-324,1.7e + 308];

需要将int转换为double。