I want to generate an array with n random numbers (i.e. n calls to Math.random()). I don’t care about whether they are unique or not.
Currently I’m using a loop:
let numbers = [];
for (let i = 0; i < n; ++i) {
numbers.push(Math.random());
}
I’d just like to know if this can be vectorised – for example in other languages I’d expect something like Math.random(n) to produce an array of n random numbers. Or is a loop the way to go in Javascript?
cheers.
This way or another you will still get a loop somewhere underneath – even if there is any “vectorization” library for javascript, it will boil down to the loop.