The following code will generate a series of at least 5000 random numbers
of four digits each between 0 and 1 without repeating in either dBASE III
or CLIPPER.

==========================================================================

The first section tests for whether or not the program is compiled and
sets up memory variables for the index files as well as the calculation of
the random numbers using either the dBASE or the CLIPPER modulus functions.

PUBLIC clipper
IF clipper
    STORE 'ntx' TO mext
    STORE 'mseed%5000' TO mscalc
    STORE '(21*mx + 2001)%5000' TO mrcalc
ELSE
    STORE 'ndx' TO mext
    STORE 'mod(mseed,5000)' TO mscalc
    STORE 'mod(21*mx + 2001,5000)' TO mrcalc
ENDIF clipper

==========================================================================

The next section generates a reasonably random seed number from the
time and date functions and calculates the first random number based on
the 'mscalc' calculation above, with the memory variable 'mx' being
the random number at this point, and the number ranging from 0 to 5000.
The routine should be run once before generating the series of random
numbers.

* PROCEDURE seed
* procedure to calculate seed number
CLEAR
SET DECIMALS TO 4
STORE time() to mtime
STORE dtoc(date()) to mdate
STORE 3 * val(substr(mtime,8,1)) + val(substr(mdate,8,1)) TO mseed
STORE 3 * mseed + val(substr(mtime,7,1)) TO mseed
STORE 3 * mseed + val(substr(mdate,7,1)) TO mseed
STORE 3 * mseed + val(substr(mtime,5,1)) TO mseed
STORE 3 * mseed + val(substr(mdate,5,1)) TO mseed
STORE 3 * mseed + val(substr(mtime,4,1)) TO mseed
STORE 3 * mseed + val(substr(mdate,4,1)) TO mseed
STORE 3 * mseed + val(substr(mtime,2,1)) TO mseed
STORE 3 * mseed + val(substr(mdate,2,1)) TO mseed
STORE 3 * mseed + val(substr(mtime,1,1)) TO mseed
STORE 3 * mseed + val(substr(mdate,1,1)) TO mseed
PUBLIC mx
STORE &mscalc TO mx
* RETURN

=========================================================================

The final section may be used in a loop or at any point an additional
number is needed.  As can be seen, the next random number is generated
from the last, and then divided by 5000 to yield the output between
0 and 1.
 
STORE &mrcalc TO mx
STORE mx/5000 TO mrand

=========================================================================
dBASE III is a trademark of ASHTON TATE and CLIPPER is a trademark of
NANTUCKET


This code is placed in the Public Domain and may be copied and modified
freely provided it is not sold.  It is offered as is with no guarantees
whatsoever.

                                J. Eliot B. Moss

                                      and

				William E. Moss
