Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

手写获取随机数函数 #23

Open
Hongbusi opened this issue Jun 28, 2022 · 1 comment
Open

手写获取随机数函数 #23

Hongbusi opened this issue Jun 28, 2022 · 1 comment
Labels

Comments

@Hongbusi
Copy link
Member

Hongbusi commented Jun 28, 2022

function getRandom (min, max) {
  return Math.floor(Math.random() * Math.abs(max - min + 1) + min)
}
@Hongbusi Hongbusi added handwritten-code today 每日一题。 JS javascript labels Jun 28, 2022
@Rainer-Yu
Copy link

Rainer-Yu commented Jun 28, 2022

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))
}

@Hongbusi Hongbusi removed the today 每日一题。 label Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants