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

问题描述 投票:0回答:1

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

javascript random
1个回答
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。

© www.soinside.com 2019 - 2024. All rights reserved.