I try to run the number generator and it works correctly but sometimes it returns repeated numbers. I have tried some options but it keeps going the same way or it removes some number. What is the best alternative?
function sorteio() {
const numeroAleatorio = (min, max) => {
return Math.floor(Math.random() * 59 + 1)
};
const gerarNumerosEntre1a60 = n => {
const resultado = [];
for (let i = 0; i < n; ++i) {
resultado.push(numeroAleatorio(1, 60));
}
return resultado;
}
document.getElementById("resultado").innerHTML = gerarNumerosEntre1a60(6);
}
<button onclick="sorteio()">Sortear numeros!</button>
<h1 id="resultado"></h1>