TechTalK: Random Number Generator in RPG/400

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: