MDN 文档中是这样介绍的:该Math.random()
函数返回0-1范围内的浮点伪随机数(包括0,但不包括1),在该范围内具有近似均匀的分布 - 然后可以缩放到所需范围。该实现选择初始种子到随机数生成算法; 它不能被用户选择或重置。
随机生成10以内任意长度的随机数
function getRandomInt(len) { let arr = Array.from({length:len},() => Math.random()*10|0); console.log(arr) }
function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive }
原文:https://www.cnblogs.com/-constructor/p/10732908.html