My function is working fine but needs to return 6 different random numbers, and eventually returns a pair of similar numbers. I tried to make it pass a simple condition if / else to run. If it doesn t pass, it is called again until the condition is satisfied.
Any suggestios how else to make sure my random function returns 6 different random numbers?
const randomNum = function() {
var al1, al2, al2, al4, al5, al6;
function ran() {
al1 = Math.floor((Math.random()*60)+1);
al2 = Math.floor((Math.random()*60)+1);
al3 = Math.floor((Math.random()*60)+1);
al4 = Math.floor((Math.random()*60)+1);
al5 = Math.floor((Math.random()*60)+1);
al6 = Math.floor((Math.random()*60)+1);
}
ran()
if(al1 != al2 || al2 != al3 || al3 != al4 || al4 != al5 || al5 != al6) {
//do my code
} else {
ran()
}
}
Aucun commentaire:
Enregistrer un commentaire