Following up on this answer for creating an array of specified length, I executed the below to get a corresponding result but filled with random numbers, instead of zeros.>
var randoms = Array(4).fill(Math.floor(Math.random() * 9));
This line of code will create a list of 4 of the same number because fill takes a single value and repeats it for the length of the list. What you want to do is run the random number generator each time:
var makeARandomNumber = function(){
return Math.floor(Math.random() * 9);
}
var randoms = Array(5).fill(0).map(makeARandomNumber);
console.log(randoms)
// => [4, 4, 3, 2, 6]
https://jsfiddle.net/t4jtjcde/