dimanche 22 février 2015

Call random function Javascript, but not twice the same function

I use a function that randomly selects another function, which works. But sometimes it runs the same function twice or even more often in a row.


Is there a way to prevend this?


My current code:



window.setInterval(function(){
var arr = [func1, func2, func3],
rand = Math.floor(Math.random() * arr.length),
randomFunction = arr[rand];
randomFunction();
}, 5000);


Pretty simple so far. But how do I prevent func1 (for example) to run twice in a row





Aucun commentaire:

Enregistrer un commentaire