title: Random image on HTML refresh
body: <p>I have this website where when you refresh it will bring up a random image from a JS array, here's the code </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Refresh for image!&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;script type="text/javascript"&gt;
  &lt;!--
   var imlocation = "images/";
   var currentdate = 0;
   var image_number = 0;
   function ImageArray (n) {
     this.length = n;
     for (var i =1; i &lt;= n; i++) {
       this[i] = ' '
     }
   }
   image = new ImageArray(13)
   image[0] = '1.jpg'
   image[1] = '2.jpg'
   image[2] = '3.jpg'
   image[3] = '4.jpg'
   image[4] = '5.jpg'
   image[5] = '6.jpg'
   image[6] = '7.jpg'
   image[7] = '8.jpg'
   image[8] = '9.jpg'
   image[9] = '10.jpg'
   image[10] = '11.jpg'
   image[11] = '12.jpg'
   image[12] = '13.jpg'
   image[13] = '14.jpg'
   image[14] = '15.jpg'
   image[15] = '16.jpg'
   image[16] = '17.jpg'
   image[17] = '18.jpg'
   image[18] = '19.jpg'
   var rand = 60/image.length
   function randomimage() {
      currentdate = new Date()
      image_number = currentdate.getSeconds()
      image_number = Math.floor(image_number/rand)
      return(image[image_number])
   }
   document.write("&lt;img src='" + imlocation + randomimage()+ "'&gt;");
  //--&gt;
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've been looking at different ways to make the code alot less clunky and more uniform. I want to be able to just dump .png, .jpg and .gif files into the folder without me having to manipulate the code each time to add the new image in an array. I also found that despite being random I get the same image alot on each refresh, think this is based on the method I used to randomise the image. </p>
  
  <p>Can anyone help with the idea of dumping the files inside a folder and letting the code do the work rather than an array and could anyone please help me with the randomising of each image.</p>