title: JavaScript generate random numbers without repeating
body: <p>I have some code where I have an array of x amount of items. In this case, videos, and I want to randomly call a video, however if the current video already called is the same as the random number I want it to generate another random number until it's unique.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>var videoLinks = [
      ['&lt;iframe id="vid" src="https://www.youtube.com/embed/nYm2G4MnSkY?autoplay=1" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'],
      ['&lt;iframe id="vid" src="https://www.youtube.com/embed/wAgZVLk6J4M?autoplay=1&amp;start=5&amp;end=45" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'],
      ['&lt;iframe id="vid" src="https://www.youtube.com/embed/ix9wpslKwBE?autoplay=1" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'],
      ['&lt;iframe id="vid" src="https://www.youtube.com/embed/OJJ-iLsQOPc?autoplay=1&amp;iv_load_policy=3" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'],
      ['&lt;iframe id="vid" src="https://www.youtube.com/embed/rore790l_sk?autoplay=1&amp;start=12&amp;end=94" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'],
  ];
  
  var randomNumber = function () {
      var getRandomNumber = Math.floor(Math.random() * 5);
      var random = videoLinks[getRandomNumber]
      document.getElementById("videoWrapper").innerHTML = random[0];
  };
  
  randomNumber(); // To call the function on load
  </code></pre>