javascript how to generate 1 random integer code example
Example 1: javascript generate a random integer number in a range of numbers
const min = 1;
const max = 4;
const intNumber = Math.floor(Math.random() * (max - min)) + min;
console.log(intNumber); //> 1, 2, 3
Example 2: javascript random number 1 or -1
//an equation that returns either 1 or -1
var number = ((Math.floor(Math.random() * 2) - 2) * 2) + 1