Random Number in JS

Math.random() returns a decimal number from 0 up to but not including 1.

Common Patterns

Math.random() // 0 <= value < 1
Math.random() * 6 // 0 <= value < 6
Math.floor(Math.random() * 6) // integer from 0 to 5
Math.floor(Math.random() * 6) + 1 // integer from 1 to 6

Random Number Between Min and Max

const min = 50
const max = 100
 
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min
console.log(randomNumber)