I am trying to generate random numbers using Math.random() that are logged / or written in random intervals...
I wrote the following:
function ranNum () {
setInterval( function () {
var myNum = Math.round(Math.random()*100000);
document.write(myNum+' ');
return myNum;
}, ranNum)
}
ranNum();
but the intervals are not random, in fact they seem to be null or zero, as there are endless numbers printed... I guess it's not possible to call a new instance of the ranNum function so the second parameter of setInterval is either 0 or always the same..
I was told recursion would be the solution here but fail to implement it.
setTimeoutinsteadsetInterval