× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: How to retrieve a random number in COBOL/CL/API call
  • From: "Lynnette Procopio" <LPROCOPI@xxxxxxxxxxxxxxxxxxxxx>
  • Date: Wed, 23 May 2001 09:12:44 -0500

Here are some resources to try:

I dug through the NEWS/400 archives and found an RPG III and RPG/400 routine 
published in September 1989 that generates random numbers. The RANDOM routine 
can be downloaded from 
http://www.as400network.com/noderesources/code/clubtechcode/random.rpg . 
A companion routine, RAN_DEMO, is available at 
http://www.as400network.com/noderesources/code/clubtechcode/ran_demo.rpg . 
RAN_DEMO shows how to call routine RANDOM and generate (1) a random list of 
whole numbers from 1 to an upper limit, (2) a random list of whole numbers from 
a lower limit to an upper limit, and (3) a random identifier that can be used 
as an AS/400 password
___________________________________________________________
RANDOM NUMBER GENERATOR IN RPG IV
The RPG IV program below supports the math bindable API CEERAN0 (Basic Random 
Number Generation). The input parameter C0Seed has a valid range of 0 to 
2,147,483,646; when the value is 0, the API generates a seed from the system's 
current Greenwich mean time. On return, CEERAN0 changes the value so it can be 
used as the new seed in a subsequent call.

Output parameter C0RndNbr is a 64-bit double floating-point number with a value 
between 0 and 1. If an invalid seed is used, -1 is returned.

The program logic is based on the minimum and maximum values for the random 
number generation. These values are initialized in the D-specs. The program 
uses the %DecH built-in function to convert the floating-point random number 
into a packed decimal with a length of 30 digits and 29 decimal positions. It 
then multiplies this value by the maximum value: Because 1 is the highest 
possible random number, the result will never be greater than the maximum 
value. The program's Do loop ensures that the random number generation is 
repeated until the result is higher than or equal to the minimum value.

D C0Seed          S              5I 0 Inz(0)
D C0RndNbr        S              8F
 **-- Random Number Conversion:  ---------------------------------- **
D RndNbr          S             10I 0
D MaxNbr          S             10I 0 Inz(9000000)
D MinNbr          S             10I 0 Inz(1000000)
 **
  
**==================================================================**
 **
C                   DoU       RndNbr >= MinNbr
 **
C                   CallB     'CEERAN0'
C                   Parm                    C0Seed
C                   Parm                    C0RndNbr
C                   Parm                    *OMIT
**
C                   Eval      RndNbr = %DecH(C0RndNbr:30:29) * MaxNbr
C                   EndDo
 **
C                   Return

___________________________________________________________
RANDOM NUMBER GENERATOR IN ILE CL (OPM callable)
------------------------------------------------------------------*/
/* Generates a random number between 0 and 1.                       */
/* This is a bound ILE CLP program and requires these compile steps */
/* 1. CRTCLMOD                                                      */
/* 2. CRTPGM RANDOM MODULE(RANDOM) SRVPGM(QLEMF)                    */
/*                                                                  */
/* The first parameter is returned as a FLOAT8 (aka FLOAT BIN(53))  */
/* The second is a seed value. After, the SEED value is modified by */
/* this program.                                                    */
/*------------------------------------------------------------------*/
RANDOM: PGM (&RTNVAL &SEED)
DCL &RTNVAL *CHAR (8)
DCL &SEED *CHAR (4)

CALLPRC PRC(CEERAN0) PARM(&SEED &RTNVAL)
ENDPGM

___________________________________________________________
RANDOM NUMBER GENERATOR IN COBOL/400
Download the program at 
http://www.etk.com/download/etkpak/etkpak.htm#MATHPK .



Lynnette Procopio
Information Technology
Kansas City Missouri School District
Phone: (816) 418-7132
Fax:      (816) 418-7104
e-mail:   lprocopi@email.kcmsd.k12.mo.us
Web:    www.kcmsd.k12.mo.us


>>> Tom.Masters@EmersonTransportation.com 05/23/01 08:36AM >>>
Is there a function somewhere in OS/400 to call which will return a random
number?

Thanks,

Tom Masters
Mgr. Information Systems
Emerson Transportation Division
(314) 506-2380 (Voice)
(314) 506-2620 (Fax)
Tom.Masters@emersontransportation.com 

+---
| This is the COBOL/400 Mailing List!
| To submit a new message, send your mail to COBOL400-L@midrange.com.
| To subscribe to this list send email to COBOL400-L-SUB@midrange.com.
| To unsubscribe from this list send email to COBOL400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com 
+---END

+---
| This is the COBOL/400 Mailing List!
| To submit a new message, send your mail to COBOL400-L@midrange.com.
| To subscribe to this list send email to COBOL400-L-SUB@midrange.com.
| To unsubscribe from this list send email to COBOL400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---END


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.