Creating a small application to generate random numbers. See the fiddle here.
Having an issue with the function that generates the numbers. There are 3 variables that control the output. The count of the numbers in a set/sequence, the number of the sets, and a number to limit the generated number, max number.
I created 2 loops to generate the numbers in sets. The inner loop creates a set of numbers (an array), and the outer loop adds that set to setArr, another array.
So I created 2 arrays. The one that will hold the current generated set temp, and the one that will hold the whole sets, setsArr.
Inner loop creates a set, and the outer loop pushes the created set to setsArr. And before executing again I empty the temp array. So this goes on and on.
But this doesn't work. I must be missing something. Any help?
function gen() {
var cols = document.getElementById("cols").value;
var sets = document.getElementById("sets").value;
var max = document.getElementById("max").value;
var setsArr = [];
var temp = [];
for (var i = 0; i < sets; i++) {
for (var j = 0; j < cols; j++) {
var num = Math.floor(Math.random() * max);
temp.push(num);
}
setsArr.push(temp);
temp.length = 0;
}
console.log(setsArr);
}