I\'d like to know how to achieve: generate a random number after a random number of time. And reuse it.
function doSomething(){
// ... do something.....
Just throwing my hat in the ring
var keepLooping = true;
(function ontimeout(){
if(keepLooping){
doTheAction();
setTimeout(ontimeout, Math.random() * 100);
}
})();
depends if you want to put doTheAction() inside the setTimeout callback or not. I think it's fine to put it before/outside. If you want the initial delay, then put it inside, if not, put it outside for simplicity.