Generate random whole numbers within a range javascript
function randomRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(randomRange(1,9));
Generate random whole numbers within a range javascript
function randomRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(randomRange(1,9));
javascript random int in range
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
console.log(randomInt(1, 6)) // random integer between 1 and 6
Random number given a range js
const randomNumber = ({ min, max } = { min: 0, max: 1 }) => {
if (min >= max) {
throw Error(
`minimum value (${min}) is larger than or equal to maximum value (${max})`
);
}
return Math.floor(Math.random() * Math.floor(max - min + 1) + min);
};
// Usage: random number between 10 and 100.
const n = randomNumber({ min: 10, max: 100 });
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us