I'm in the early stages of learning JavaScript and I had thought of making a lottery number generator for practice. This is what I have so far (z is for the total lottery balls, and y for the number of digits to be generated):
function generateRandomNumbers(z,y){
var resultArray = [];
var output = "";
if(isNaN(z) || isNaN(y)){
return "You have entered an invalid value";
}else{
for(x=0; x<y; x++){
var result = Math.ceil(Math.random()*z);
resultArray.push(result);
output += resultArray[x]+ "\n";
}
}
return output;
}
The problem is, this doesn't prevent duplicates from occurring. What could be a good way to ensure that the array's content doesn't contain any duplicates? I apologize if this has already been asked before.