title: Unique Random Number Generator Javascript
body: <p>I'm trying to make a bingo game for fun. I've looked in a lot of places for a unique generator but I can't seem to find one. I've tried to make my own,but once it actually hits a number that's the same it does an infinite loop. I've tried a simple code that in theory should work but for some reason things pass through. What can I do!?</p>
  
  <pre><code>var bc = [];
  for (var i = 0; i &lt; 5; i++) {
    var r = Math.floor(Math.random()*20+1) + 0;
    if(!(r in bc)){
      bc.push(r);     
      }
      else
      {
      i--;
      }
  }
  ____________________________________________
  ____________________________________________
  ____________________________________________
  b1=0;
  b2=0;
  b3=0;
  b4=0;
  b5=0;
  var bc = [b1,b2,b3,b4,b5]
  var bnc = function(){
      var n = Math.floor(Math.random() * 5+1)+0;
      var n2 = Math.floor(Math.random() * 5+1)+0;
      b1 = n;
      var a1 = true;
      var as = false;
      while(a1){
          var c = n;
          if(c===b1||c===0 ||as!==false){
          c = n2;
          as=true;
          }
          if(c===b1||c===0&amp;&amp;as===true){
          c = n;
          as=false;
          }
              if(c!=b1){
              b2 = c;
              a1 = false;
              a2 = true;
          }
      }
  };
  bnc();
  console.log("new1");
  console.log(b1,b2,b3,b4,b5);
  //_______________________________________
  var bnc2 = function(){
      var n = Math.floor(Math.random() * 5+1)+0;
      var n2 = Math.floor(Math.random() * 5+1)+0;
      var a1 = true;
      var as = false;
      while(a1){
          var c = n;
          if(c===b1||c===b2||c===0&amp;&amp;as===false){
          c = n2;
          as=true;
          }
          if(c===b1||c===b2||c===0&amp;&amp;as===true){
          c = n;
          as=false;
          }
          if(c!=b1&amp;&amp;c!=b2){
              b3 = c;
              console.log("made it 1");
              a1 = false;
          }
      }
  };
  bnc2();
  console.log("new2");
  console.log(b1,b2,b3,b4,b5);
  </code></pre>