So trying to figure out what is special about rand() mod k7 in C. In another post someone said that C rand() uses http://en.wikipedia.org/wiki/Linear_congruential_generator but I don't see what makes (mod k7) k-> scalar special for the algorithm associated to ANSI C.
So I have the following code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
void getRand(int* num1, int* num2, int* num3);
int main(int argc, const char * argv[])
{
int i = 0;
for (i = 0; i < 100; i++) {
srand(time(NULL));
printf("%d\n", rand() % 7 );
sleep(1);
}
return 0;
}
This always prints 3. But if I use any n such that 7 does not divide n, I get a better sequence of first values. Still obviously not random but better then just 3 or some c mod 7 = 3.
I deliberately made the program this way with the seed in the loop to show that the first value always returns 3 regardless of the seed.
Yes I could get random numbers for Xn n > 0
but I want X1 % 7 != X1 % 7
for each Xo.