I'm trying to find a better way to fill an array using JavaScript.
Currently I have a function that looks like this to generate a fixed size array of sample data. I need the sample data to be not the same (non-homogenous) and preferably pseudo-random.
function () {
var arraySize = (1024 * 10) / 4; // Get size for 10k buffer
var testdata = new Uint32Array(arraySize);
for (var i = 0; i < arraySize; i++) {
testdata[i] = Math.random() * 0xFFFFFFFF;
};
//...
};
And it works, but I suspect it's not very idiomatic for JavaScript.
My broader concern is that for the tests I'm running, I'm going to need larger (and larger!) arrays so I'm concerned about saturating the system for an otherwise temporary object.
Is there a more efficient / idiomatic approach to filling an array?