I have made a function that generates a random number and, from that number, pulls a name from a list if criteria is met. BUT, I am questioning its capability. I know with computers, the numbers generated are more psuedo-random than "pure" random.
The function is:
Code:
int random(int copy_n, int n; char **names, char **save)
{
int i, max;
double j;
unsigned int iseed = (unsigned int)time(NULL);
srand(iseed);
while(1){
for(i = 0; i < n; ++i){
/* Generate a random number between 0 and 1. */
j = (double)(rand()/((double)RAND_MAX + 1));
// printf ("The random number generated is %lf \n", j);
if(j <= .1){
// printf("---> Value of random number is less than");
// printf(" or equal .1 with value of %lf.\n", j);
strncpy(save[cap], names[i], 4);
max += 1;
if(max == copy_n){ // if max is equal to the amount to copy
break;
}
}
}
if(cap == copy_n) break;
}
return 0;
}