title: Generate a random array in C
body: <p>I'm developing in C using OpenVMS, I've done a code that put in a 1001 (0-1000) elements array, 1000 (0-999) random numbers between 0 and 50. Here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  main(){
      int vet[1000], fre[50];
      int i;
  
      srand(time(NULL));
  
      for(i=0;i&lt;1000;i++){
          vet[i]=(rand()%51);
      }
  
      for(i=0;i&lt;1000;i++){
          printf("%d\n", vet[i]);
      }
  
      for(i=0;i&lt;1000;i++){
          fre[vet[i]]=fre[vet[i]]+1;
      }
  
      for(i=0;i&lt;51;i++){
          printf("The number %d  was generated %d times\n", i, fre[i]);
      }
  }
  </code></pre>
  
  <p>When I show how much times each number was generated, I saw that the number 50 has a big number, sometimes more than double than others numbers, someone can help me?</p>
  
  <p><strong>SOLVED Code that works</strong> I must use srand() for now</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  main(){
          int vet[1000], fre[51] = {0};
          int i;
  
          srand(time(NULL));
  
          for(i=0;i&lt;1000;i++){
                  vet[i]=(rand()%51);
          }
  
  for(i=0;i&lt;1000;i++){
  printf("%d\n", vet[i]);
  }
  
          for(i=0;i&lt;1000;i++){
                          fre[vet[i]]=fre[vet[i]]+1;
          }
  
          for(i=0;i&lt;51;i++){
                  printf("The number %d  was generated %d times\n", i, fre[i]);
          }
  }
  [EOB]
  </code></pre>
  
  <p><strong>Thank you all</strong></p>