<!-- ONE STEP TO INSTALL UNIQUE RANDOM NUMBERS:
1. Copy the coding into the HEAD of your HTML ******** -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML ******** -->
<HEAD>
<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Barry Pranklin :: http://www.pranklin.com */
var Found=false
var Current = new Array()
var MaxValue=100 //(Example 2 is equal to: 0,1,2)
var NumUnique=3 //The number of unique numbers required
var Count=0
var Current = new Array(NumUnique)
GetUnique()
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>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.31 KB -->