Ok I seem to have a further problem, with the rand function. It produces the same set of random numbers in the same order every time it get's called. Now if I use the srand(time(NULL)) to create a different seed every time. The time function seems to return the same number every time and therefore produce the same random number every time.
The above produces: 9,3,14,4,1,12,6,14 everytimeCode:#include <stdlib.h> char* LB_Random(char *maxR,char *dummy) { int i; static char n[10]; int rMax = atoi(maxR); rMax++; i = rand() % rMax; sprintf(n,"%d",i); return n; }
Produces the number 5 everytime, due to the time function returning the same number.Code:#include <stdlib.h> char* LB_Random(char *maxR,char *dummy) { int i; static char n[10]; int rMax = atoi(maxR); rMax++; srand(time(NULL)); i = rand() % rMax; sprintf(n,"%d",i); return n; }



LinkBack URL
About LinkBacks


