+ 1

# How does random work in JS?

2 Answers

+ 21

Math.random() gives a random number between 0 and 1 (like : 0.35333543)
Math.round(Math.random()*(b-a)+a)
//random rounded number between "a" and "b"

+ 3

Ok thanks!

+ 1

2 Answers

+ 21

Math.random() gives a random number between 0 and 1 (like : 0.35333543)
Math.round(Math.random()*(b-a)+a)
//random rounded number between "a" and "b"

+ 3

Ok thanks!