title: remove duplicate numbers from randomly generated array
body: <p>I am learning C++, and came across an idea about how to remove duplicates from a randomly generated integer array with values from 0 to 100. I coded it like this, but I see that some numbers are repeating. I really can't figure out the bug. Please help.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  int main()
  {
    srand(time(NULL));
    int item[100];
    int z;
    int count = 0;
  
    for (z = 0; z &lt; 100; z++) {
      item[z] = rand() % (z + 1);
      count++;
      cout &lt;&lt; item[z] &lt;&lt; endl;
    }
  
    cout &lt;&lt; "Total = ";
    cout &lt;&lt; count &lt;&lt; endl;
    int i, j;
    int NewLength = 1;
  
    for (i = 1; i &lt; 100; i++) {
      for (j = 0; j &lt; NewLength; j++) {
        if (item[i] == item[j])
          break;
      }
  
      if (j == NewLength)
        item[NewLength++] = item[i];
    }
  
    for (int x = 0; x &lt; 100; x++) {
      cout &lt;&lt; item[x] &lt;&lt; endl;
    }
  }
  </code></pre>