当前位置 : 主页 > 网络编程 > JavaScript >

Generate Number With Random In JS

来源:互联网 收集:自由互联 发布时间:2021-06-30
Generate Float // (0, 1)Math.random();// (0, max)Math.random() * max// (min, max)Math.random() * (max - min) + min Generate Int // (0, 1) no integer between 0 and 1// (0, max)parseInt(Math.random() * max); // include 0, but not include maxp
Generate Float
// (0, 1)
Math.random();

// (0, max)
Math.random() * max

// (min, max)
Math.random() * (max - min) + min
Generate Int
// (0, 1) no integer between 0 and 1

// (0, max)
parseInt(Math.random() * max); // include 0, but not include max
parseInt(Math.random() * (max + 1)); // include 0 and max

// (min, max)
parseInt(Math.random() * (max - min) + min); // include min, but not include max
parseInt(Math.random() * (max - min + 1) + min); // include min and max
上一篇:defineGetter
下一篇:vscode setting
网友评论