Created
August 22, 2016 02:34
-
-
Save bmoren/dad0f6abee6f9eae84600d02f4ed231b to your computer and use it in GitHub Desktop.
non repeating random, more efficiently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pRandom = 1; | |
var total = 5; // top end of range | |
var rand = Math.floor( Math.random()*total ); //get a rand | |
while(rand == pRandom){ //are we the same, if so try again until we are not. | |
rand = Math.floor( Math.random()*total ); //get a new random if we are the same | |
console.log("try again"); | |
} | |
pRandom = rand; //store the current random number to check against next time. | |
console.log(rand); // output / do something with the # | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment