math random jjs code example
Example 1: math.random javascript
Math.random()
Math.floor(Math.random() * 10)
Math.floor(Math.random() * 11)
function randomNum(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
Example 2: random number javascript
function uniqueNumber(count) {
let defaultNumber = 4413277523420
let convertToArray = defaultNumber.toString().split("")
let sliceNumber = convertToArray.slice(0, count)
let randomNumber = Math.floor((Math.random() * +sliceNumber.join("")));
if (randomNumber.toString().split("").length < count) {
randomNumber = Math.abs(randomNumber - +sliceNumber.join(""))
}
return randomNumber
}