Welcome to Jokes2000. Tips for improving your website: Graphic, HTML and javascript A fine collection of cartoons Jokes jokes jokes - get a good laugh Joke of the day and mailing list Table of contents
Jokes2000.com Jokes2000.com
 

Random Numbers Up One Level.

Using javascript, you can easily get a random number. Just copy one one the functions below. To get a random number, just call CreateRandomNumber(Min, Max). The call returns a random number between Min and Max -- both included.

Simple version that does not work with Netscape 2:

<script language=javascript type="text/javascript">
<!--
function CreateRandomNumber(Min, Max) 
{ var range = Max-Min+1;
  return (Math.floor(Math.random() * 
          Math.pow(10,("" + range).length)) % range) + parseInt(Min);
}
// -->
</script>


Advanced version that works with all javascript enabled browsers:

<script language=javascript type="text/javascript">
<!--
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;
}

function CreateRandomNumber(Min, Max) 
{ var rand = new RandomNumberGenerator();
  return Math.round( (Max-Min) * rand.next() + Min );
}
// -->
</script>


Affiliate Sites: Funny Videos | Fight Videos | Free Arcade Games


welcome | cartoons | jokes | daily jokes | sitemap | search | feedback | what's new

Copyright © 1997-2007 Real Comedy Inc.