/* * for make * * gcc -o mul32 mul32.c * strip mul32 * * for call by perl * $seed = 1 ; for ( $i = 0 ; $i < 10 ; $i ++ ) { open(RAND,"./mul32 $seed |") ; $seed = ; print "$i $seed\n" ; close(RAND) ; } */ #include #include #include #define NUM1 69069L #define NUM2 1566083941L int main(int argc, char* argv[]) { char seedbuf[64] ; char multbuf[64] ; char* dmyptr ; unsigned long val ; unsigned long mul ; switch (argc) { default: printf("Usage: %s [] []\n", argv[0]) ; break ; case 1: fgets(seedbuf, sizeof seedbuf, stdin) ; break ; case 2: strncpy(seedbuf, argv[1], sizeof seedbuf) ; break ; case 3: strncpy(seedbuf, argv[1], sizeof seedbuf) ; strncpy(multbuf, argv[2], sizeof multbuf) ; break ; } seedbuf[(sizeof seedbuf) - 1] = '\0' ; multbuf[(sizeof multbuf) - 1] = '\0' ; val = strtoul(seedbuf, &dmyptr, 10) ; mul = strtoul(multbuf, &dmyptr, 10) ; if (mul <= 0) mul = NUM2 ; val = (val * mul + 1) & 0xFFFFFFFFL ; printf("%lu", val) ; }