title: How to fill an array with random values from a range? (Duplicates are OK.)
body: <p>I am new to C++, I have a problem of array manipulation. I have an array of X with length 100, I need to fill the value of X with integer value of 1 to 10 (1,2,3,4,5,6,7,8,9,10) randomly.
  I know that there will be duplicate, maybe like 1 printed ten times, etc, but that's really what I want.</p>
  
  <p>Here is what I have:</p>
  
  <p>an array of X: </p>
  
  <pre><code>int X[100];
  </code></pre>
  
  <p>Here is my code snippet:</p>
  
  <pre><code>int* X = NULL;
  int* val = NULL;
  int length1= 100;
  int length2= 10;
  X = new int[length1];
  val = new int[length2];
  int i;
  int j;
  
  for (i = 0; i &lt; isi; i++) {
      val[i] = i;
      for (j = 0; j &lt; length1; j++) {
          if (j &gt; i) {
              X[j] = val[i];
          } else {
              X[j] = val[0];
          }
          cout &lt;&lt; "X[" &lt;&lt; j &lt;&lt; "] = " &lt;&lt; X[j] &lt;&lt; "\n";
          Sleep(1);
      }
  }
  </code></pre>
  
  <p>Code above makes the array X from index 0 to 99 has value of 0, then index 0 to 99 has value of 1 and so the other index until the index 0 to 99 has value of 9. </p>
  
  <p>This is not what I want, what I want is to make it (if it is not random) index 0 to 9 has value of 0, then 10 to 19 has value of 1 ... until index 90 to 99 has value of 9. Hope my explanation clear.</p>
  
  <p>I have come to a question in stackoverflow: <a href="https://stackoverflow.com/questions/22797177/how-would-you-make-an-array-of-10000-with-only-values-of-1-1000-inclusive">How would you make an array of 10000 with only values of 1-1000 inclusive?</a></p>
  
  <p>But still can't resolve my problem my self.
  Can someone please give me solution to this.</p>
  
  <p>Thank you in advance</p>