Skip to content

Instantly share code, notes, and snippets.

@darrenfu
Created August 21, 2014 02:55
Show Gist options
  • Save darrenfu/e4622aba3ff958f74308 to your computer and use it in GitHub Desktop.
Save darrenfu/e4622aba3ff958f74308 to your computer and use it in GitHub Desktop.
To generate a four digit number that doesn't repeat in each digit.
var nums = new Array();
for (var i=0;i<10;i++){
nums.push(i);
}
var outputs = [0,0,0,0];
for (var j=0;j<4;j++){
var idx = (Math.random() * nums.length) | 0;
outputs[j] = nums[idx];
nums.splice(idx,1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment