title: How do I fill an array with random numbers such that they are different?
body: <p>I have a task where I have to fill an array with 16 random numbers, in random indexes.</p>
  
  <p>4 of those elements have to be -1, and all the other left indexes have to be 0-15, but different from another, meaning it is impossible for two different indexes have the same number (0-15). </p>
  
  <p>Filling 4 random indexes is easy, and so is filling the other indexes with random numbers between 0-15, but how do I feel them in such way that they are necessarily different from each other?</p>
  
  <p>There are also two more conditions which complicate this task much more, the first one is that the number of the index cannot have the same number within it, meaning <code>arr[3] == 3</code> is impossible, and another condition is that </p>
  
  <pre><code>    (m[p] == j &amp;&amp; m[j] == mp &amp;&amp; m != j)
  </code></pre>
  
  <p>is something that we must take care of so it won't happen. For example, if <code>arr[2] == 0</code> and <code>arr[0] == 2</code>, we have to change it so it won't happen.</p>
  
  <p>I'm so confused, I had literally sat 8 hours yesterday in front of this, trying all sort of things, and I have no idea, honestly..</p>
  
  <pre><code>void FillArray(int *sites, int length) 
  {
      int checkarr[N] = { 0 };
      int i, 
          cnt = 0, 
          j = 0, 
          t = 0, 
          k, 
          times = 0;
      int *p = sites;
  
      while (cnt &lt; C)
      {
          i = rand() % length;
          if (p[i] - 1)
              cnt = cnt;
          p[i] = -1;
          cnt++;
      }
  
      while (j &lt; length) 
      {
          if (p[j] == -1) j++;
          else 
          {
              p[j] = rand() % length;
              checkarr[p[j]]++;
              j++;
          }
      }
  
      j =0;
      while (j&lt;length)
      {
          for (k=0; k&lt;length;k++)
          {
              while (checkarr[k] &gt; 1)
              {
                  while (t &lt; length) 
                  {
                      if (p[j] == p[t] &amp;&amp; p[j] != -1 &amp;&amp; j != t)
                      {
                          checkarr[p[t]]--;
                          p[t] = rand() % length;
                          checkarr[p[t]]++;
                          times++;
                      }
                      else t++;
                  }
  
                  if (times &lt; 11) 
                  { 
                      j++;
                      t = 0;
                      times = 0;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I tried using the Fisher-Yates shuffle method, but for somereason it doesn't even fill the array. I don't know why </p>
  
  <p>while (j
  
  <pre><code>    if (p[j] == -1)
          j++;
      else {
          while (m &lt; length) {
              m = rand() % length;
              if (helpingArray[m] != -2)
              {
                  p[j] = helpingArray[m];
                  helpingArray[m] = -2;
                  j++;
              }
              else if (helpingArray[m] == -2)
              {
                  j = j;
              }
  
              for (w = 0; w &lt; length; w++)
              {
                  if (helpingArray[w] == -2)
                      count++;
              }
              if (count == 12) {
                  m = length;
              }
          }
      }
  }
  }  
  </code></pre>