javascript javascript生成一个两位数的正随机数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15735159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:53:51  来源:igfitidea点击:

javascript generate a two digits positive random number

javascriptfunctionrandom

提问by Yasmine Ra'fat

I am new to javascript and I need help to implement a simple function that generates a random positive number that consists of only 2 digits. Can anyone help me please?

我是 javascript 新手,我需要帮助来实现一个简单的函数,该函数生成一个仅包含 2 位数字的随机正数。有人可以帮我吗?

回答by metadept

For a random number between 10 and 99, use:

对于 10 到 99 之间的随机数,请使用:

Math.floor(Math.random() * 90 + 10)

jsFiddle demo: http://jsfiddle.net/zjLY6/

jsFiddle 演示:http: //jsfiddle.net/zjLY6/

回答by ama2

Try

尝试

Math.random().toFixed(2)*100