Random picture on my page: how ?

toast

Gone !
This my actual code: do you see any problems ? Any improvements to make ?

Code:
 // Random picture<br>

var ic = 10; // Number of alternative images<br>
var table = new Array(ic); // Array to hold filenames<br>
<br>
table[0] = &quot;images/photo1.jpg&quot;;
table[1] = &quot;images/photo2.jpg&quot;;
table[2] = &quot;images/photo3.jpg&quot;;
table[3] = &quot;images/photo4.jpg&quot;;
table[4] = &quot;images/photo5.jpg&quot;;
table[5] = &quot;images/photo6.jpg&quot;;
table[6] = &quot;images/photo7.jpg&quot;;
table[7] = &quot;images/photo8.jpg&quot;;
table[8] = &quot;images/photo9.jpg&quot;;
table[9] = &quot;images/photo10.jpg&quot;;

function pickRandom(range) {
 if (Math.random)
  return Math.round(Math.random() * (range-1));
 else {
  var now = new Date();
  return (now.getTime() / 1000) % range;
 }
}

var choice = pickRandom(ic);	// Write out IMG tag using a randomly-chosen image name.
 
Do you know any way to improve the code ? Do you see any flagrant, awkward coding in my method ?
How do you proceed yourself ? Do you know any faster code ? Can you indicate any URLs with interesting code that perform random pictures display ?

[Random pictures = each time you load a HTML page, it displays a different picture]
 
Back
Top