Last active
August 29, 2015 14:06
-
-
Save Buooy/8b0ffb8c61ad25241e04 to your computer and use it in GitHub Desktop.
Generates a Random Set of Unique Numbers within a range
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
| // Credits to http://stackoverflow.com/questions/2380019/generate-8-unique-random-numbers-between-1-and-100 | |
| function generate_unique_random( set_length, max_range ){ | |
| var arr = [] | |
| while(arr.length < set_length){ | |
| var randomnumber=Math.ceil( Math.random() * max_range ) | |
| var found=false; | |
| for(var i=0;i<arr.length;i++){ | |
| if(arr[i]==randomnumber){found=true;break} | |
| } | |
| if(!found)arr[arr.length]=randomnumber; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment