Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Random file on page load... or at least that was the idea :(


  • From: javascript@xxxxxxxxxx (McCoy, Thomas)
  • Subject: [Javascript] Random file on page load... or at least that was the idea :(
  • Date: Thu, 17 Oct 2002 11:38:51 -0700

Thanks Harry!  The "random number" was exactly what I was looking for.

Am I correct in saying that the other code was randomly selecting a movie
based on the date and time?  (Sorry to be a bother, but I'm trying to learn
as I go here)
 
 
Sincerely,
Thomas McCoy

-----Original Message-----
Thomas, a quick question for you: are you looking for a random number,
or a number based on the time of day?

If you want a random number (to pick a random file from your array), try
this:

// replace all of this
len = movies.length;
today=new Date();
today=today.getTime()/10;
temp_number=today%len;
rnd = Math.round(temp_number);

// with this one line
rnd = (Math.floor(Math.random() * movies.length));