title: How to use function srand() with time.h?
body: <p>My program contains code that should generate a random positive integer number every time I execute it. It generates random numbers but only once. After that, when I execute same code, it gives me same values, and it is making my code useless.</p>
  
  <p>I started with the <strong>rand</strong> function, and then I used the <strong>srand()</strong> function with the <strong>time.h</strong> header file, but still it is not working properly.</p>
  
  <pre><code>#define size 10
  for(i=0;i&lt;size;i++)
      Arr[i] = rand()%size;
  </code></pre>
  
  <p>First call (random):</p>
  
  <pre><code>6 0 2 0 6 7 5 5 8 6
  </code></pre>
  
  <p>Second call (random but same as previous):</p>
  
  <pre><code>6 0 2 0 6 7 5 5 8 6
  </code></pre>
  
  <hr>
  
  <p>Later I visited Stack Overflow questions and I read about the srand() function, and I used it as:</p>
  
  <pre><code>#include&lt;time.h&gt;
  for(i=0;i&lt;size;i++)
      Arr[i] = srand(time(NULL));
  </code></pre>
  
  <p><strong>First call:</strong></p>
  
  <pre><code>-10327 -10327 -10327 -10327 -10327 -10327 -10327 -10327 -10327 -10327
  </code></pre>
  
  <p><strong>Second call:</strong></p>
  
  <pre><code>-10326 -10326 -10326 -10326 -10326 -10326 -10326 -10326 -10326 -10326
  </code></pre>
  
  <p>It is giving me different (but not random values). I've defined <strong>Arr[i] as unsigned int</strong>, and still I am getting negative values.</p>