📜  js 范围内的随机数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:19.438000             🧑  作者: Mango

代码示例6
var min = 10, max = 25;
//inclusive random (can output 25)
var random = Math.round(Math.random() * (max - min) + min);
//exclusive random (max number that can be output is 24, in this case)
var random = Math.floor(Math.random() * (max - min) + min);
//floor takes the number beneath the generated random and round takes
//which ever is the closest to the decimal