title: Non repeating Random Numbers 2D Vector (C++)
body: <p><em>EDIT</em>: I am currently working on a project. I am almost finished, although I can not seem to figure out how to populate my vector(matrix) with non repeating random numbers. I am getting random numbers, but some of them are repeating. I tried implementing a method that checks to see if a number pushed to the vector already exists, but that does not work.</p>
  
  <p>Is there an easy way to go about this?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  /*
  The purpose of this program is to create a matrix using 2D vectors, then decide
  if it is a perfect matrix or not.
  */
  
  void matrix(int );
  
  int main()
  {
      int input;
      char again = 'y';
  
      cout &lt;&lt; "Welcome to my perfect matrix program. The function of the program is"
              "\nto:"
              "\n"
              "\n   1. Allow the user to enter the size of the perfect matrix, such as"
              "\n      N. N&gt;=2."
              "\n   2. Create a 2 D vector array of size N x N."
              "\n   3. Populate the 2 D vector array with distinct random numbers."
              "\n   4. Display the sum for each row, column, and diagonals then"
              "\n      determine whether the numbers in N x N vector array are perfect"
              "\n      matrix numbers.";
      cout &lt;&lt; endl &lt;&lt; endl;
  
      while(again == 'y' || again == 'Y')
      {
          cout &lt;&lt; "\nEnter the size of the matrix : ";
          cin &gt;&gt; input;
  
          while(input &lt; 2)
          {
              cout &lt;&lt; "\nError *** Incorrect input - You entered a number &lt; 2"
                      "\nEnter a Positive integer Number &gt;= 2: ";
              cin &gt;&gt; input;
          }
  
          matrix(input);
  
          cout &lt;&lt; "\nWould you like to find another perfect matrix?"
                  "\nEnter y || Y for yes or n || N for no: ";
          cin &gt;&gt; again;
  
          if(again == 'N' || again == 'n')
          {
              cout &lt;&lt; "\nThis perfect matrix algorithm is implemented by B"
                      "\nFebruary 13th - 2017\n";
          }
  
          while(again != 'Y' &amp;&amp; again != 'y' &amp;&amp; again != 'N' &amp;&amp; again != 'n')
          {
              cout &lt;&lt; "\nError *** Invalid choice - Must enter y|Y or n|N" &lt;&lt; endl;
              cout &lt;&lt; "\nWould you like to find another perfect matrix?"
                      "\nEnter y || Y for yes or n || N for no: ";
              cin &gt;&gt; again;
          }
      }
  
      return 0;
  }
  
  void matrix(int value)
  {
      int N = value;
      bool isPerf = true;
      int sum = 0,
          i,
          j;
  
      int diagSum1 = 0,
          diagSum2 = 0;
  
      vector&lt;vector&lt;int&gt; &gt;arr;
  
      srand(time(0));
  
      for(i = 0; i &lt; N; i++)
      {
          vector&lt;int&gt; temp;
          bool check;
          int digit;
          for(j = 0; j &lt; N; j++)
          {
              do
              {
                  digit = rand()%8;
                  check = true;
                  for(int k = 0; k &lt; j; k++)
                  {
                      if(digit == temp.front())
                      {
                          check = false;
                          break;
                      }
                  }
              }while(!check);
              temp.push_back(digit);
          }
          arr.push_back(temp);
      }
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "The perfect matrix that is created for size " &lt;&lt; value &lt;&lt; ":";
      cout &lt;&lt; endl &lt;&lt; endl;
  
      for(i = 0; i &lt; arr.size(); i++)
      {
          for(j = 0; j &lt; arr[i].size(); j++)
          {
              cout &lt;&lt; arr[i][j];
              cout &lt;&lt; "   ";
          }
          cout &lt;&lt; endl &lt;&lt; endl;
      }
  
      for(i = 0; i &lt; arr.size(); i++)
      {
          for(j = 0; j &lt; arr[i].size(); j++)
          {
              sum += arr[i][j];
          }
      }
      int perf = sum/3;
  
      cout &lt;&lt; "The perfect number is: " &lt;&lt; perf &lt;&lt; endl &lt;&lt; endl;
  
      for(i = 0; i &lt; arr.size(); i++)
      {
          int rowSum = 0;
          for(j = 0; j &lt; arr[i].size(); j++)
          {
              rowSum += arr[i][j];
          }
          cout &lt;&lt; "Sum of numbers in Row # " &lt;&lt; i + 1 &lt;&lt; " = " &lt;&lt; rowSum;
          if(rowSum != perf)
          {
              isPerf = false;
          }
          cout &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
  
  
      for(i = 0; i &lt; arr.size(); i++)
      {
          int colSum = 0;
          for(j = 0; j &lt; arr[i].size(); j++)
          {
              colSum += arr[j][i];
          }
  
          cout &lt;&lt; "Sum of numbers in Column # " &lt;&lt; i + 1 &lt;&lt; " = " &lt;&lt; colSum;
          if(colSum != perf)
          {
              isPerf = false;
          }
          cout &lt;&lt; endl;
      }
      cout &lt;&lt; endl;
  
  
  for(i = 0; i &lt; arr.size(); i++)
  {
          diagSum1 += arr[i][i];
          diagSum2 += arr[i][arr.size() - i - 1];
  }
  
  cout &lt;&lt; "Sum of numbers in first diagonal    =   " &lt;&lt; setw(3) &lt;&lt; diagSum1 &lt;&lt; endl;
  if(diagSum1 != perf)
      {
          isPerf = false;
      }
  cout &lt;&lt; "Sum of numbers in second diagonal   =   " &lt;&lt;  setw(3) &lt;&lt; diagSum2 &lt;&lt; endl;
  if(diagSum2 != perf)
      {
          isPerf = false;
      }
  
  cout &lt;&lt; endl;
  
  if(isPerf)
  {
      cout &lt;&lt; "The above is a perfect matrix" &lt;&lt; endl;
  }
  else
      cout &lt;&lt; "The above is not a perfect matrix" &lt;&lt; endl;
  
  cout &lt;&lt; endl;
  </code></pre>
  
  <p>}</p>