developer-plus / interview

https://interview.developer-plus.org
MIT License
9 stars 1 forks source link

手写获取随机数函数 #23

Open Hongbusi opened 2 years ago

Hongbusi commented 2 years ago
function getRandom (min, max) {
  return Math.floor(Math.random() * Math.abs(max - min + 1) + min)
}
Rainer-Yu commented 2 years ago
function getRandom() {
    const ran = parseInt(10*Math.random())
    const ran2 = parseInt(10*Math.random())+1
    const temp = crypto.getRandomValues(new Uint32Array(ran))[ran-1]
    return parseInt((temp+'').substring(0,ran2))
}