'Generate a two-digit positive random number in JavaScript [closed]
How can I implement a simple function in JavaScript that generates a random positive number that consists of only two digits?
Solution 1:[1]
For a random number between 10 and 99, use:
Math.floor(Math.random() * 90 + 10)
jsFiddle demo: http://jsfiddle.net/zjLY6/
Solution 2:[2]
Try
Math.random().toFixed(2)*100
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | metadept |
Solution 2 | ama2 |