mardi 26 décembre 2017

How to find previous randomly generated number using Math.random in a setInterval function?

I am generating a random number between 1 and 13. This works fine. What I want to do is not generate the same number as the immediate previous number.

function showRandomDotIcon() {
    var randomDot = Math.floor(Math.random() * 13) + 1;
    console.log(randomDot);
}

setTimeout(showRandomDotIcon, 3500);

So something like:

if(randomDot == previousDot) {
    // skip to next number
}




Aucun commentaire:

Enregistrer un commentaire