× 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.



The following code will work on any COBOL compiler:

01  RANDOM-VARIABLES.
     02  RANDOM-PRECISION        PIC S9(7)  COMP  VALUE +9999999.
     02  RANDOM-INTEGER          PIC S9(7)  COMP  VALUE   ZERO.
     02  RANDOM-MODULUS          PIC S9(7)  COMP  VALUE +2099863.
     02  RANDOM-MULTIPLIER       PIC S9(7)  COMP  VALUE +1005973.
     02  RANDOM-INCREMENT        PIC S9(7)  COMP  VALUE  +443771.
     02  RANDOM-QUOTIENT         PIC S9(7)  COMP  VALUE   ZERO.
     02  RANDOM-PRODUCT          PIC S9(15) COMP  VALUE   ZERO.
     02  RANDOM-ADJUST           PIC S9(9)  COMP  VALUE +2099863.
     02  RANDOM-SEED              PIC S9(7) COMP.
     02  RANDOM-RESULT          PIC S9(9)V9(9) COMP.

 RANDOM-FUNCTION.
     MOVE RANDOM-SEED TO RANDOM-INTEGER

     COMPUTE RANDOM-PRODUCT  = RANDOM-INCREMENT
                             + RANDOM-MULTIPLIER * RANDOM-INTEGER
     COMPUTE RANDOM-QUOTIENT = RANDOM-PRODUCT    / RANDOM-MODULUS
     COMPUTE RANDOM-INTEGER  = RANDOM-PRODUCT
                             - RANDOM-QUOTIENT   * RANDOM-MODULUS
     COMPUTE RANDOM-RESULT   = RANDOM-INTEGER    / RANDOM-ADJUST

     MOVE RANDOM-INTEGER TO RANDOM-SEED
    .


start by putting a SEED value in RANDOM-SEED. This could be time of day
or anything else you like. Then each time you PERFORM RANDOM-FUNCTION
the data-item RANDOM-RESULT will contain a new pseudo-random value
between 0 and 1. To get an integer X between 1 and 47 (say):
COMPUTE X = RANDOM-RESULT * 47 + 0.5




----- Original Message -----
From: Winchester Terry <terry.winchester@raymondcorp.com>
To: <cobol400-l@midrange.com>
Sent: Friday, August 24, 2001 8:35 AM
Subject: RE: RANDOM function with COBOL400?


> Kelly,
>
> AFAIK you must call the CEERAN0 API to get random numbers
> in ILE/Cobol (at least up thru V4R5).
>
> Try this link at News400:
>
> http://www.as400network.com/Forums/Search_Results.cfm?CFApp=19#Message57169
>
> if this doesn't work, look at http://www.as400network.com/as400forums/
> and access the Cobol forum, then search for "random".  If your still
> having a problem, let me know and I'll send it to you.
>
> Terry
>
>
> -----Original Message-----
> From: Kelly Cookson [mailto:kc62301@yahoo.com]
> Sent: Friday, August 24, 2001 9:10 AM
> To: COBOL400-L@midrange.com
> Subject: RANDOM function with COBOL400?
>
>
> Newbie question.
>
> I have to generate a list of randomly selected
> employees for drug testing.  I was thinking of using
> the RANDOM function.  Unless someone has a better
> idea! :)
>
> I can't seem to get the RANDOM function coded
> properly.  When I code the following line using SEU:
>
>      COMPUTE X = FUNCTION RANDOM.
>
> SEU highlights the line and gives the following error
> message:
>
> "ANS COBOL reserved word FUNCTION will be accepted as
> a nonreserved word. A period is required before
> RANDOM. Line rejected."
>
> I tried coding the variation:
>
>     COMPUTE X = RANDOM.
>
> and got the error message:
>
> "RANDOM not arithmetic expression. Line rejected."
>
> What am I missing here?  How do I use the RANDOM
> function in COBOL400?
>
> Thanks in advance.
> Kelly
>
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
> _______________________________________________
> This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing
list
> To post a message email: COBOL400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/cobol400-l
> or email: COBOL400-L-request@midrange.com
> _______________________________________________
> This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing
list
> To post a message email: COBOL400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/cobol400-l
> or email: COBOL400-L-request@midrange.com
>



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.