Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random string generator

Status
Not open for further replies.

staceybauer

Instructor
Aug 19, 2003
9
US
We have a request to generate a random alphanumeric string of characters for our business using VS COBOL II (MVS) on the mainframe. Any ideas if there are any random character generating functions available in COBOL?
 
Why are you still using the (currently unsupproted by IBM) VS COBOL II compiler? If you were using IBM's currently supported (strategic) compiler "Enterprise COBOL", you would have "native" language support for the RANDOM intrinsic function.

If you are still using the VS COBOL II compiler *but* are using the LE (Language Environment) run-time, then you should look at:

CEERAN0 callable service - see:




Bill Klein
 
Actually it is supported until December 2004 and we are preparing to migrate sometime in 2004. It did not provide any new functionality that we needed, so we chose to put the cost of migration off for a few years. I was already aware of the callable service for random number generating you indicated above, however I thought there may be a random alphanumeric character generator that I was not aware of. I can use the random number generator and a few pieces of code to create my own generator easy enough.

Thanks for your response non-the-less.

Stacey
 
Correction to my last post.

End of Service for VS COBOL II R4 was:

2001/03/31

(still WELL past)

Bill Klein
 
Oh yes,
I neglected to mention in my second post that we have been running our VS COBOL II applications using the LE runtime since 1999. As I understand VS COBOL II running WITH LE run-time is supported until December 2004.

Sorry about any confusion.

Stacey
 
Well, yes and no.

The OBJECT code produced by VS COBOL II is supported when running with the LE run-time library (as is OS/VS COBOL object code) - and there is no announced (2004 or later) drop date for this.

HOWEVER, the compiler itself is no longer supported. Therefore, if you have any "new" hardware, interfaces (such as CICS), etc that causes a "compile-time" problem, you are already out-of-luck.

HOWEVER, as you are using the LE run-time library, you should look into the CEERAN0 routine that I mentioned above. You *may* be able to do a dynamic (not static) CALL to it.

Bill Klein
 
What is the set of characters to be in the string? Letters, digits, any printable character, any EBCDIC character?
 
Only Uppercase A-Z and numbers 0-9. I was thinking I would like to make it any printable EBCDIC character and add some logic (parameters) that could filter it to what you want. We have something working now. I was hopeful there would be a simple function call to do this however.
 
My suggestion is to generate random numbers(see earlier threads on this), then map them into the 36 characters as folows:
[tt]
77 NDX PIC S9(4) COMP.
77 RANDOM-NUMBER PIC S9(9) COMP.
77 RANDOM-JUNK PIC S9(9) COMP.
77 RANDOM-MOD PIC S9(4) COMP.
01 VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.
05 CVT-CHAR PIC X(1) OCCURS 36 TIMES.
01 OUTPUT-STRING.
05 OUTPUT-CHAR PIC X(1) OCCURS nn TIMES.
. . . .
PERFORM VARYING NDX FROM 1 BY 1 UNTIL NDX > nn
get random number
DIVIDE 36 INTO RANDOM-NUMBER GIVING RANDOM-JUNK
REMAINDER RANDOM-MOD
ADD 1 TO RANDOM-MOD
MOVE CVT-CHAR(RANDOM-MOD) TO OUTPUT-CHAR(NDX)
END-PERFORM
[/tt]
 
I guess great minds think alike :)

I did something very similar.

3000-GENERATE-CHARACTER.

COMPUTE SA-RANDOM-NUMBER = FUNCTION RANDOM.

* IF ALREADY SEEDED, DON'T NEED THE PARAMETER
* create the seed date by taking the time out of the
* CURRENT-DATE field
MOVE FUNCTION CURRENT-DATE TO CURRENT-DATE.

COMPUTE SA-RANDOM-NUMBER = FUNCTION RANDOM (CD-SEED).

COMPUTE SS-TC = SA-RANDOM-NUMBER
* NUMBER-CHARACTERS
+ +1.

MOVE TC-CHARACTER (INDX) TO RANDOM-CHARACTER.

3000-EXIT.
EXIT.

The TC-CHARACTER was a table of characters similar to what you had. And we did a perform... varying by the number of characters we wanted in the string.

You probably could tell that from my first reply on Aug 19 I would do something similar.

Thanks for the reply wabbit. :)

stACEy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top