HP3000-L Archives

July 1999, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tom Renz <[log in to unmask]>
Reply To:
Date:
Wed, 28 Jul 1999 12:58:31 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (18 lines)
Connie,

Using the functions available for COBOLII (COBOL '85) you can get a random number.  You need to enable it by using the "$CONTROL POST" compile option.  I generally put it at the top of the source code.  In the WORKING-STORAGE section you need to specify a field as a "V9(x)" type field where 'x' is any number of digits you desire then "call" the function using the COMPUTE statement.

Say your field is RAND-NUM PIC V9(5) and the COMPUTE statement looks like "COMPUTE RAND-NUM = FUNCTION RANDOM(seed)".  The 'seed' value is any number between 0 and 999999999.  You can "hard-code" in the numeric value or if you want some for of randomness you can you a field and move some number (ie. TIME-OF-DAY or some other random type number) to the field for the seed value.

The random number returned is a number less than zero, explaining the assumed decimal point in the PICture clause for the numeric field.  Once you have the number you can do a little multiplication to get the desired number.  For a 4 digit number multiply the random number by 10,000 to get an integer number.

Hope this helps.

Tom Renz

>>> Connie Sellitto <[log in to unmask]> 07/28/99 12:29PM >>>

Writing in COBOLII on an HP3000 937, I need a routine to generate a 4-digit
random number, either on the fly, or to set up as a table.  Any
suggestions?

ATOM RSS1 RSS2