try
#include <time.h>
#include <stdio.h>
int i=0;
int random();
int main(){
srand(time(NULL));
random();
return 0;
}
int random(){
int a;
i+=1;
a=rand()%20;
printf("This is the %d th iteration\n",i);
printf("random number generated is: %d\n",a);
if(a<8)
random();
}
The problem is with srand(). the random number generator is not random, it is pseufo-random, it means that if you set the seed 2 times with same value, you will get the same 'random' sequence. And since your seed is a number of seconds, you get every time the same sequence.