title: How does srand() work?
body: <p>This is my code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  int main(){
  float m, n;
  printf("Enter n, m:");
  scanf("%f %f", &amp;n, &amp;m);
  int l;
  l=m-n;
  int i;
  for(i=0; i&lt;4; i++){
      srand(time(NULL));
      double r=rand();
      r/=RAND_MAX;
      r*=l;
      r+=n;
      printf("%f ", r);
  }
  return 0;
  }
  </code></pre>
  
  <p>Why it generates same numbers? and when I write <code>srand(time(NULL));</code>before the loop it generates different numbers! why it is like this? how does this program work?</p>