I have an array :
var array = new Array();
Here is the random function, which gives a random number between min
and max
(seen in a previous Stackoverflow topic) :
function randomIntFromInterval(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
This array is meant to have 9 cells. I would like to populate it with random number, with the important condition that each of those number are unique, which means a number in this array cannot be found twice or more.So finally, here is where I am stuck (whole code) :
var array = new Array();
function randomIntFromInterval(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
// populate the variable "array" with 9 different
// random numbers
function randomlyInitializeArray() {
var random = 0;
// For each cell (9 cells) in my "array"
for (var i = 0; i < maxLength; i++) {
// Return a number between 1 & 9
random = randomIntFromInterval(1, maxLength);
/* Verifying if this random number is already in
the "array" /!\ stuck here /!\ */
}
}
So, what is the logic for populate an array with 9 unique (different) number ?