Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript generate a two digits positive random number [closed]

How can I implement a simple function in JavaScript that generates a random positive number that consists of only two digits?

like image 667
Yasmine Ra'fat Avatar asked Mar 31 '13 22:03

Yasmine Ra'fat


2 Answers

For a random number between 10 and 99, use:

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

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

like image 184
metadept Avatar answered Nov 16 '22 02:11

metadept


Try

Math.random().toFixed(2)*100
like image 6
ama2 Avatar answered Nov 16 '22 01:11

ama2