Possible Duplicate:
Generating random numbers in Javascript in a specific range?
Can some one tell me how to get one digit random number(1,2,3,.. not 0.1,0.2,.. or 1.0,5.0,..) using Math.random() or some other way in javascript?
Math.random()
returns a float between 0
and 1
, so just multiply it by 10
and turn it into an integer:
Math.floor(Math.random() * 10)
Or something a little shorter:
~~(Math.random() * 10)