Office of Information Services - Application Programming

References - Randon Number Generation


Date: Wed, 15 Nov 2000 13:49:58

Mike Brennan to Kathy Sanley:

Recall that several months ago I helped you with random number generation for (I believe) generating PINs. While the solution I came up with was ok as a stopgap measure, I was not particularly happy with it. I've since come up with a better way to generate random numbers for future applications. (It would also be worthwhile to modify the original application to use this new procedure).

I recommend that the procedure I describe here ALWAYS be used instead of the INFO/BASIC RND() function. That's because this new procedure uses a very secure seed and also, unlike RND(), uses a cryptographically secure pseudorandom number generator.

Please forward this email to whomever you deem appropriate.


There are two subroutine calls you need to use:

CALL *PSU.RND(RESULT, LIMIT)
CALL *RAND.DESTROY

Doing:

CALL *PSU.RND(RESULT, LIMIT)

is semantically equivalent to doing:

RESULT = RND(LIMIT)

See the description of RND() in the INFO/BASIC manual for more info.

Note that the generator used here is self-seeding; you need not and cannot specify a seed. Also note that the seed is always unique, so you can't use PSU.RND() to generate a repeatable sequence as you can with RND().

A generator is automatically created, initialized, and seeded the first time you call PSU.RND(). The generator remains in memory and uses system resources even when you're not using it--even after your program finishes. So once you have finished your random number generation, it's a good idea to call RAND.DESTROY to free up those resources. A new generator will then be created next time you call PSU.RND.

EXAMPLE: The following program prints 6-digit pseudorandom numbers between 100000 and 999999 inclusive:

0001: RESULT = ""
0002: *
0003: FOR I = 1 TO 20
0004: CALL *PSU.RND(RESULT, 900000)
0005: PRINT RESULT + 100000
0006: NEXT I
0007: *
0008: CALL *RAND.DESTROY
0009: *
0010: END
Back to Top


Tools Library Menu

Application Tools- Cleanup Tools- OS.LIB- PSU.LIB- Paragraphs- Program Lists- References Menu- Search Tools- Skin Menu Maker- Subroutines