title: How to randomize the carousel function below?
body: <p>Below is the code that i have to rotate images on my site. However, i am having trouble trying to get it to randomize the starting image.</p>
  
  <pre><code>&lt;script&gt;
  // Automatic Slideshow - change image every 4 seconds
  var myIndex = 0;
  carousel();
  
  function carousel() {
    var i;
    var x = document.getElementsByClassName("mySlides");
    for (i = 0; i &lt; x.length; i++) {
      x[i].style.display = "none";
    }
    myIndex++;
    if (myIndex &gt; x.length) {myIndex = 1}
    x[myIndex-1].style.display = "block";
    setTimeout(carousel, 4000);
  }
  &lt;/script&gt;
  </code></pre>