lib/libc/stdlib/random.c
/*
 * random:
 *
 * If we are using the trivial TYPE_0 R.N.G., just do the old linear
 * congruential bit.  Otherwise, we do our fancy trinomial stuff, which is
 * the same in all the other cases due to all the global variables that have
 * been set up.  The basic operation is to add the number at the rear pointer
 * into the one at the front pointer.  Then both pointers are advanced to
 * the next location cyclically in the table.  The value returned is the sum
 * generated, reduced to 31 bits by throwing away the "least random" low bit.
 *
 * Note: the code takes advantage of the fact that both the front and
 * rear pointers can't wrap on the same call by not testing the rear
 * pointer if the front one has wrapped.
 *
 * Returns a 31-bit random number.
 */
If we are using the trivial TYPE_0 R.N.G., just do the old linear
congruential bit.  Otherwise, we do our fancy trinomial stuff, which is
the same in all the other cases due to all the global variables that have
been set up.  The basic operation is to add the number at the rear pointer
into the one at the front pointer.  Then both pointers are advanced to
the next location cyclically in the table.  The value returned is the sum
generated, reduced to 31 bits by throwing away the "least random" low bit.

the code takes advantage of the fact that both the front and
rear pointers can't wrap on the same call by not testing the rear
pointer if the front one has wrapped.

Returns a 31-bit random number.
If we are using the trivial TYPE_0 R . N . G . just do the old linear congruential bit . Otherwise we do our fancy trinomial stuff which is the same in all the other cases due to all the global variables that have been set up . The basic operation is to add the number at the rear pointer into the one at the front pointer . Then both pointers are advanced to the next location cyclically in the table . The value returned is the sum generated reduced to 31 bits by throwing away the " least random " low bit . the code takes advantage of the fact that both the front and rear pointers can ' t wrap on the same call by not testing the rear pointer if the front one has wrapped . Returns a 31 - bit random number .
long
random()
{
	register long i;
	register long *f, *r;
	if (rand_type == TYPE_0) {
		i = state[0];
		state[0] = i = (i * 1103515245 + 12345) & 0x7fffffff;
	} else {
		f = fptr; r = rptr;
		*f += *r;
		i = (*f >> 1) & 0x7fffffff;	
		if (++f >= end_ptr) {
			f = state;
			++r;
		}
		else if (++r >= end_ptr) {
			r = state;
		}
		fptr = f; rptr = r;
	}
	return(i);
}
long random ( ) { register long i ; register long * f , * r ; if ( rand_type == TYPE_0 ) { i = state [ 0 ] ; state [ 0 ] = i = ( i * 1103515245 + 12345 ) & 0x7fffffff ; } else { f = fptr ; r = rptr ; * f += * r ; i = ( * f >> 1 ) & 0x7fffffff ; if ( ++ f >= end_ptr ) { f = state ; ++ r ; } else if ( ++ r >= end_ptr ) { r = state ; } fptr = f ; rptr = r ; } return ( i ) ; }
random:
 If we are using the trivial TYPE_0 R.N.G., just do the old linear
 congruential bit.
random : If we are using the trivial TYPE_0 R . N . G . just do the old linear congruential bit .
/*
		 * Use local variables rather than static variables for speed.
		 */ /* chucking least random bit */