-1
For(i=0 to 10)
  printf(%d\t%d,rand()%100,rand()%100);

It always prints the same set of values. Can someone explain to me why?

Narf
  • 14,600
  • 3
  • 37
  • 66

1 Answers1

0

The rand() function generates random numbers with a given "seed" number. When you dont specify the seed rand() will give you the same output every time. To set a seed use srand(time(NULL)); to make use of the computers internal clock to set the seed. Dont forget to include time.h in order to have access to the time() function.

VTodorov
  • 953
  • 1
  • 8
  • 25