JS 1到10随机数,2到10随机数

  • Math.random() 返回一个0~1之间的随机数;

  • Math.floor() 向下取整;

  • Math.ceil() 向上取整;

  • Math.round() 四舍五入;

  • Math.fround() 32位浮点数;

1~10随机数

let num = Math.floor(Math.random() * 10 + 1)

2~10随机数

let num = Math.floor(Math.random() * 9 + 2)

一种生成随机数的方法

// array 里面生成10个随机数,循环数组既可以获取;
const array = new Uint32Array(10);
window.crypto.getRandomValues(array);
posted @ 2022-08-30 14:45  DL·Coder  阅读(1680)  评论(0编辑  收藏  举报