Search code examples
mainframerexx

REXX routine that will return a unique string


I want to define a function that returns an unique string each time it is called. The return value of this function needs to be unique for the next 50 years. Here is what I have tried:

k.rand=USERID()
do i=1 to 10 by 1
 n=RANDOM(1,26)
k.i=word('a b c d e f g h I j k l m n o p q r s t u v w x y z ',n)
m.i= WORD('@ ! # $ % ^ * 1 2 3 4 5 6 7 8 9',i)
k.rand=k.rand ||k.i ||m.I
END
say k.rand

Solution

  • At our site, there are some REXX tools, which when invoked, will submit Mainframe jobs. For example, if you invoke the tool against a dataset, a job will be submitted in the background to find the count of records in the dataset.

    At a given time, the REXX tool can be invoked N number of times. In order to avoid duplication of job names in spool, we came up with something like the below.

    NUM = RANDOM(000,999)
    JOBNAME=USERID()||NUM    
    

    Both USERID() and RANDOM() are built in functions in REXX.

    USERID() returns the TSO/E user ID. More details here.

    RANDOM returns a random number. More details here.

    A code snippet is provided here for you to try.