title: Generating unique random numbers in C
body: <p>I tried generating 10 unique random numbers in C. I have an array <code>numout[]</code> for 10 numbers but this gets to "segmentation fault" after some time.</p>
  
  <p>Tho code is:</p>
  
  <pre><code>int i,j,numout[10],randnum;
  
  void main()
  {
      srand(time(NULL));  
      for(i=0;i&lt;10;i++)
      {
          numout[i]=generate();
          printf("%d",numout[i]);
          fflush(stdout);
          sleep(1);
          printf("\b");
      }
  }
  int generate()
  {
      randnum=1+(int)(rand()*mul_val/(RAND_MAX+1.0));
      for(j=0;j&lt;i;j++)
      {
          if(randnum==0 || randnum==numout[j])
          {
              randnum=generate();     
          }
      }
      return(randnum);
  }
  </code></pre>