We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
生成长度为 4 的随机数字串
String.prototype.slice.call(Math.random() * 10000, 0, 4)
之前在生成数字串时用过这个方法,后来发现会出现 453. 这样错误数字串,因为 Math.random() 生成了 0.0453xxxxxxxxxx 这样的随机数,这个数字乘以 10000 就变成 453.xxxxxxx,前面的零被吃掉了。。。
453.
Math.random()
0.0453xxxxxxxxxx
10000
453.xxxxxxx
所以正确姿势应该是介个样几
String.prototype.slice.call(Math.random(), 2, 6)
计划通 ~
The text was updated successfully, but these errors were encountered:
AymaxLi
No branches or pull requests
错误姿势
生成长度为 4 的随机数字串
之前在生成数字串时用过这个方法,后来发现会出现
453.
这样错误数字串,因为Math.random()
生成了0.0453xxxxxxxxxx
这样的随机数,这个数字乘以10000
就变成453.xxxxxxx
,前面的零被吃掉了。。。正确姿势
所以正确姿势应该是介个样几
计划通 ~
The text was updated successfully, but these errors were encountered: