I have read 90% of the mathematical analysis, but I have not studied it in depth. This code is copied, and the core part is copied. It feels good.
Generate a fixed random number sequence, as long as the seeds are the same. This random number generator is transparent and easy to change. It is good.
Every time you implement the code, you will find a lot of problems. And, once you write the code, time will fly... very good.
Okay, post it. I'm here for an Internet cafe, and I'm writing a blog while playing a movie. Haha. It's good.
/* 10-35-11-2-08-20.11.c -- Chapter 10, question 1 */<br/> # include <stdio. h> </P> <p> # define false (0) <br/> # define true (1) <br/> # define a (48271l) <br/> # define M (2147486647l) <br/> # define Q (m/a) <br/> # define R (M %) </P> <p> unsigned long int seed; </P> <p> int main (void); <br/> int eatenter (void ); <br/> void initialize (unsigned long int initial_value); <br/> double random (void); </P> <p> int main (void) <br/ >{< Br/> unsigned long int initial_value; <br/> char ch; </P> <p> printf ("Please input a initial value (> = 0, enter 'q' to quit .): "); <br/> while (scanf (" % lu ", & initial_value )! = 0) <br/>{< br/> printf ("initial value has been initialized is: % lu/N", initial_value); <br/> eatenter (); <br/> initialize (initial_value); <br/> puts ("Enter 'q' to input a new initial value and enter any key else to generate a random value again. "); <br/> while (CH = getchar ())! = 'Q') <br/>{< br/> If (true = eatenter () <br/> break; <br/> printf ("It is % lf. /n ", random (); <br/>}< br/> printf (" Please input a initial value (> = 0, enter 'q' to quit .): "); <br/>}</P> <p> return 0; <br/>}</P> <p> int eatenter (void) <br/>{< br/> If ('q' = getchar () <br/> return true; <br/> else <br/> return false; <br/>}</P> <p> void initialize (unsigned long int initial_value) <br/>{< br/> seed = initial_value; <br/>}</P> <p> double random (void) <br/>{< br/> unsigned long int temp_seed; </P> <p> temp_seed = A * (seed % q)-R * (seed/Q); <br/> If (temp_seed> = 0) <br/> seed = temp_seed; <br/> else <br/> seed = temp_seed + m; </P> <p> return (double) seed/m; <br/>}