The most common method of generating the random number sequence
In (1), integer arithmetic is used to avoid
roundoff error, the value for
For example, if the subroutine has c=1, a=4, M=9 built
in, and you supply

Note that you obtain the same result for the mod operation by just subtracting M until any further subtractions would leave a negative number (what remains is the remainder).
The rule (1) produces integers in the range
Your computer probably has a built in random number generator which may well be better than the one you choose by chance. You should check this out in the manual pages (try the man command) and then test the generated sequence. These routines often have names like rand, rn, random, srand, erand, or drand. Here are two examples of how to call these routines in C and FORTRAN.
On the AIX system, the drand48 routine generates random numbers in [0,1] with good spectral properties. It uses
and 48 bit integer arithmetic. Make sure to initialize it properly by calling the subroutine srand48 to plant your seed. To be safe, you can reseed during your calculation (read manual for details).
The definition (1) will generate
Here too, floating point numbers should be used to avoid truncation.