effects due to the usage of this script or any derivative.
No warrantees for usability for any specific application
are given or implied.
You are free to use and modify this script,
if credits are kept in the source code
*/
function GetRandomURL()
{
// Put relative or full URL's in the strings below
// You can increase the number of URL's to more than 5 by adding a
// string contaijavascript:GetRandomURL()ning an URL in list below
var locationlist = new URLList (
"harpo.html",
"groucho.html",
"chico.html",
"zeppo.html",
"Scrolling Text Stationery"
);
num = Math.round ( ( rand.next() * (locationlist.count-1)) );
location.href = locationlist.list[num];
}
function URLList ()
{
var argv = URLList.arguments;
var argc = argv.length;
this.list = new Object();
for (var i = 0; i < argc; i++)
this.list[i] = argv[i];
this.count = argc;
return this;
}
//*********************************************
// Park-Miller Pseudo-Random Number Generator
// JavaScript implementation by David N. Smith
// of IBM's T J Watson Research Center
//*********************************************
function NextRandomNumber()
{
var hi = this.seed / this.Q;
var lo = this.seed % this.Q;
var test = this.A * lo - this.R * hi;
if (test > 0)
this.seed = test;
else
this.seed = test + this.M;
return (this.seed * this.oneOverM);
}
function RandomNumberGenerator()
{
var d = new Date();
this.seed = 2345678901 +
(d.getSeconds() * 0xFFFFFF) +
(d.getMinutes() * 0xFFFF);
this.A = 48271;
this.M = 2147483647;
this.Q = this.M / this.A;
this.R = this.M % this.A;
this.oneOverM = 1.0 / this.M;
this.next = NextRandomNumber;
return this;
}
var rand = new RandomNumberGenerator();
// -->
</script>
</head>
<body bgcolor="#FFFFFF">
<h1>JavaScript Random Link</h1>
<p><b>This stationery page contains a JavaScript that selects a random URL</b></p>
<p>
The script is named <b>GetRandomURL</b> and it is placed in the HEAD section of the HTML document. The script is executed by clicking on a link containing a call to GetRandomURL(). Also note the custom text in the browser's status area when the cursor is over the link.</p>
<p>
Example of this script picking a
<a href="javascript:GetRandomURL()"
onMouseOver="window.status='This link takes you to some unknown place';
return true;">random</a> page.</p>
<blockquote>
<p>
<b>How to use:</b></p>
<p>Replace the filenames inside the script with your own URLs and edit this page contents inside the <BODY> section. You can also copy the entire script to an existing page.</p>
Use code similar to this to let the user execute the script:</p>
<pre><A HREF="javascript:GetRandomURL()"
onMouseOver="window.status='This link takes you to some unknown place';
return true;">random</A>
</pre>
<p>
Note that there seems to be an undocumented limit to the number of URLs that can be placed in the list, so if you have a large number of links, (more than 40 or 50), you may need to create multiple lists and extend the function GetRandomURL() to initially select a list at random.</p>