javascript random number
snippet in javascript

how to generate a random number in javascript

user7107

//To genereate a number between 0-1
Math.random();
//To generate a number that is a whole number rounded down
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.

js random number

user5501

var random;
var max = 8
function findRandom() {
  random = Math.floor(Math.random() * max) //Finds number between 0 - max
  console.log(random)
}
findRandom()

javascript random number

user5359

var RandomNumber = Math.ceil(Math.random() * 100);              
// Returns a random number between 1 and 100

generate random numbers in js

user9171

Math.floor((Math.random() * 100) + 1);
//Generate random numbers between 1 and 100
//Math.random generates [0,1)

javascript random number

user1425

Math.random() * 10 = 0-10

javascript random number

user669

const randomVCC = () => {
	const cc = 4728398706189983
	const randomVirtualCreditCard = Math.random(cc).toString().replace('0.', '')
	const visaCreditCard = 4 + randomVirtualCreditCard
	const pattern = /\d{16}/.exec(+visaCreditCard).join('')
    return typeof +pattern === 'number' && +pattern
}
console.log(randomVCC())