I have created a random array generator by shuffling an initial array multiple times.
SHUFFLE FUNCTION
const shuffle =(array) => {
let currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
GENERATE CHROMOSOMES(This function creates an array of arrays that are shuffled from an initial one called "sequence")
const generateChromosomes = (numberOfChromosomes) =>{
const result = [];
const sequence = ["2", "3", "4"];
for(let i = 1; i < numberOfChromosomes; i++){
result.push(shuffle(sequence))
}
return(result);
}
Despite my efforts, each time I run the code, I seem to get the same array repeated 50 times. Subsequent runs give me another set of identical arrays. Any suggestions on why this might be happening?