update-interval-sp

by Miklos Nagy

JavaScript

interval(function(){
        clicking();
        
    }, rand_time_func(), 5);
    
var timerUpdate = setInterval(rand_time_func(),500); 
    
function rand_time_func(){
  return  Math.floor( (Math.random()*5000 + 1000 ) );
}

function clicking(){
  console.log("Clicked now");
}

function interval(func, wait, times){
    var interv = function(w, t){
        return function(){
            if(typeof t === "undefined" || t-- > 0){
                setTimeout(interv, w);
                try{
                    func.call(null);
                }
                catch(e){
                    t = 0;
                    throw e.toString();
                }
            }
        };
    }(wait, times);

    setTimeout(interv, wait);
};