I want to generate an array with a random number that each number is different. Could someone help me to solve this? Thanks.
var array = [];
for(var i = 0;i < 5; i++){
var a = Math.floor(Math.random() * 5);
array.push(a);
}
console.log(array);
[0,1,2,3,4]- then shuffle that array using your algorithm of choice (Fisher-Yates Shuffle recommended). This will ensure the results are unique.set = new Set(); while (set.size < 5) set.add(Math.floor(Math.random() * 5));