title: Generate two different random numbers in C
body: <p>I am trying to generate two different random numbers in C within a given range.The range is </p>
  
  <pre><code>0 to nk-1
  </code></pre>
  
  <p>But my following code sometimes works and sometimes fails.What is the reason behind this?</p>
  
  <pre><code>n1=rand()%nk;
  n2=rand()%nk;
  while(n1==n2)
  {
   srand(time(0));
   n2=rand()%nk;
  } 
  </code></pre>