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);
var array = [];
for (var i = 0; i < 10; i++) {
var a = Math.floor(Math.random() * 10);
while (array.indexOf(a) !== -1) {
a = Math.floor(Math.random() * 10);
}
array.push(a);
}
console.log(array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With