Full version: jsB@nk » Misc » Unique Random Numbers
URL: https://www.javascriptbank.com/unique-random-numbers.html
This JavaScript will obtain three unique random numbers. Unique values range from 0-100.
Full version: jsB@nk » Misc » Unique Random Numbers
URL: https://www.javascriptbank.com/unique-random-numbers.html
<script type="text/javascript"><!-- Begin/* This script and many more are available free online atThe JavaScript Source!! http://javascript.internet.comCreated by: Barry Pranklin :: http://www.pranklin.com */var Found=falsevar Current = new Array()var MaxValue=100 //(Example 2 is equal to: 0,1,2)var NumUnique=3 //The number of unique numbers requiredvar Count=0var Current = new Array(NumUnique)GetUnique()document.write("The unique numbers are: " + Current[0] + ", " + Current[1] + ", and " + Current[2])alert("The unique numbers are: " + Current[0] + ", " + Current[1] + ", and " + Current[2]); function GetUnique() { for (i=0;Count<NumUnique;Count++) { Found=false var rndValue = get_random() var j=0 for (j=0;j<Current.length;j++) { if (Current[j] == rndValue) { Found=true break } } if (Found) { Count-- } else { Current[Count]=rndValue } } } function get_random() { var ranNum= Math.round(Math.random()*MaxValue); return ranNum; }// End --></script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->