|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 701 (0x2bd)
Types: TextFile
Notes: UNIX file
Names: »rand.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦f4b8d8c84⟧ UNIX Filesystem
└─⟦this⟧ »libc/gen/rand.c«
/*
* Random number generator, of period 2 ^ 32. Returns random numbers (ints) in
* the interval [0, 2^15-1].
* The algorithm used is a linear congruential method, where the internal
* computation is done in unsigned longs (mod 2^32). The numbers from
* this sequence are right shifted 17 bits so that the most random 15
* bits are returned.
* All this is from Knuth Vol 2, 2nd ed., ch 3. The choice of multiplier
* is made from the table in 3.3.4.E, pp102.
*/
#define A 1664525L /* Multiplicative generator */
#define C 907633387L /* Additive generator */
static long seed = 1;
srand(n)
unsigned int n;
{
seed = n;
}
rand()
{
seed = seed * A + C;
return ((seed >> 17) & 077777);
}