I have a simple function generating 4 random numbers from a getRandomNumber Function when called in a for loop. How can I prevent getting the same number twice I am adding elements to the DOm but it sometimes has 2 elements in the same div I want to prevent getting the same number twice. How can I do this? For example, getting for numbers so every time my code loads the numbers would be the same.
I was experimenting with if else statements and kind of backed myself into a corner. I know this may seem like a simple problem but I'm at my wits end on this one.
function getMeARandom(min, max) {
const randomNumber = Math.floor(Math.random() * (max - min + 1) +
min);
return randomNumber;
}
function weaponsGen() {
for (let i = 0; i < 5; i++) {
let weaponPosition = getMeARandom(0, 65);
}
}