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 (Harry Love)
  • Subject: [Javascript] Random file on page load... or at least that was the idea :(
  • Date: Thu, 17 Oct 2002 11:31:50 -0700

---------------------------------------
len = movies.length;
today=new Date();
today=today.getTime()/10;
temp_number=today%len;
rnd = Math.round(temp_number); 

--------------------------------------

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));


Regards,
Harry