One such random number generator was published in DataNetwork (now MC) in December 1986, using RPGII code. It passes the spectral test used by statisticians in determining how good a random number generator is.
I have re-coded this random number generator in RPG/400 for the benefit of our AS/400 users. Program GENRNDNBR (4) is an independent callable program that you can use anytime you need a good random number. It uses three input parameters: seed (SEED), beginning number (BEGNBR) and ending number (ENDNBR). The output parameter of the program is a random number generated which will be a number between the range specified by BEGNBR and ENDNBR. If no seed is provided, a seed is generated from the system time. A beginning and ending number can be specified between the range of 1 and 999,999. If no beginning or ending numbers are specified or the beginning number is larger than the ending number, 1 and 999,999 will be the default values respectively. Once a seed is provided, the random number generated (prior to the range qualification) becomes the seed for the next number, unless you provide another seed. This allows you to obtain many random numbers in successive calls to the program without worrying about the first three parameters.
I have re-coded this random number generator in RPG/400 for the benefit of our AS/400 users. Program GENRNDNBR (Figure 4) is an independent callable program that you can use anytime you need a good random number. It uses three input parameters: seed (SEED), beginning number (BEGNBR) and ending number (ENDNBR). The output parameter of the program is a random number generated which will be a number between the range specified by BEGNBR and ENDNBR. If no seed is provided, a seed is generated from the system time. A beginning and ending number can be specified between the range of 1 and 999,999. If no beginning or ending numbers are specified or the beginning number is larger than the ending number, 1 and 999,999 will be the default values respectively. Once a seed is provided, the random number generated (prior to the range qualification) becomes the seed for the next number, unless you provide another seed. This allows you to obtain many random numbers in successive calls to the program without worrying about the first three parameters.
TechTalK: Random Number Generator in RPG/400
Figure 4 RPG/400 random number generator
C *ENTRY PLIST C PARM SEED 99 C PARM BGNNBR 60 C PARM ENDNBR 60 C PARM RNDNBR 60 C SEED IFEQ *ZERO C TIME TIME 120 C TIME MULT .000000001SEED C ENDIF C BGNNBR IFEQ 0 C ENDNBR ANDEQ0 C ENDNBR ORLT BGNNBR C Z-ADD1 BGNNBR C Z-ADD999999 ENDNBR C ENDIF C ENDNBR SUB BGNNBR RANGE 60 C ADD 1 RANGE C MULT 9821 SEED C ADD .211327 SEED C SEED MULT RANGE RNDNBR C ADD BGNNBR RNDNBR C RETRN
LATEST COMMENTS
MC Press Online