title: How to make for loop produce five unique values
body: <p>I created this code so that it will give me five value based on probability. Then insert into an array. It works but I want it to give me 5 unique value. If I used <code>array_unique()</code> it will make the output unique so the end result will be 3 or 2 or sometimes 4 value because it removes duplicates. but I want them to be 5 unique values all the time. How can I do This.</p>
  <p>This is my code</p>
  <pre><code>
  &lt;?php
  
  $random= [];
  function getRandomWeightedElement(array $weightedValues)
  {
      $array = array();
  
      foreach ($weightedValues as $key =&gt; $weight) {
          $array = array_merge(array_fill(0, $weight, $key), $array);
      }
  
      return $array[array_rand($array)];
  }
  
  global $res;
              
  for($i=0; $i&lt;5 ; $i++)
  {
      $res=getRandomWeightedElement(array('A'=&gt;0.05, 'B'=&gt;0.05,'C'=&gt;0.10,'D'=&gt;5,'E'=&gt;5,'F'=&gt;5,'G'=&gt;5,'H'=&gt;13,'I'=&gt;16,'J'=&gt;16,'K'=&gt;16.8,'L'=&gt;18));
  
      global $stopAt; 
  
      if ($res=='A') {
          $stopAt = 20;
      } else if ($res=='B') {
          $stopAt = 50;
      } else if ($res=='C') {
          $stopAt = 70;
      } else if ($res=='D') {
          $stopAt = 100;
      } else if ($res=='E') {
          $stopAt = 135;
      } else if ($res=='F') {
          $stopAt = 165;
          continue;
      } else if ($res=='G') {
          $stopAt = 190;
      } else if ($res=='H') {
          $stopAt = 230;
      } else if ($res=='I') {
          $stopAt = 265;
      } else if ($res=='J') {
          $stopAt = 292;
      } else if ($res=='K') {
          $stopAt = 320;
      } else if ($res=='L') {
          $stopAt = 350;
      } else{
          echo &quot;error&quot;;
      }
          
      $random[]= $stopAt;
  }
  
  print_r(array_unique($random));
  ?&gt; 
  </code></pre>