title: Javascript Random Image by Time
body: <p>I'm tring to show images randomly by the time. But I need a different thing.</p>
  
  <pre><code>var images = []
  images[0] = "img/y0.gif";
  images[1] = "img/y1.gif";
  images[2] = "img/y2.gif";
  images[3] = "img/y3.gif";
  images[4] = "img/y4.gif";
  
  images[5] = "img/1.jpg";
  images[6] = "img/2.jpg";
  images[7] = "img/3.jpg";
  
  usedImages = [];
  setInterval(function () {changeImage();},100);
  
  var changeImage = function () {
      var index = Math.floor(Math.random() * (images.length)),
      thisImage = images[index];
  
      usedImages.push(thisImage);
      images.splice(index, 1);
  
      if (images.length &lt; 1) {
          images = usedImages.splice(0, usedImages.length);
      }
  
      var imgStr = '&lt;img src="' + thisImage + '" alt = ""&gt;';
      document.write(imgStr); 
      document.close();
  }           
  </code></pre>
  
  <p>My codes work but if the image is a gif interval time must be 500, or if the image is image[2] time must be 500.</p>
  
  <p>How can I do it?</p>
  
  <p>Thanks..</p>