for (let i = 0; i < 3; i++) {
let number = getRandomInt(1, 5);
random.includes(number) ? random.push(number - 1) : random.push(number);
}
console.log(random);
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
const getShuffledArray = (min, max) => {
const randoms = Array(max - min + 1).fill(min).map((n, i) => n + i);
for (let i = randoms.length - 1; i > 0; i -= 1) {
const r = Math.floor(Math.random() * (i + 1));
[randoms[i], randoms[r]] = [randoms[r], randoms[i]];
}
return randoms;
}
getShuffledArray(5, 10);
// [ 6, 10, 7, 5, 8, 9 ]
getShuffledArray(5, 10);
// [ 9, 6, 5, 7, 8, 10 ]