1

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
Marc.2377
  • 7,807
  • 7
  • 51
  • 95
hotcoder
  • 41
  • 2
  • 10
  • What have you tried ???, do you want an external function written in rexx (or another language – Bruce Martin Oct 01 '18 at 12:47
  • 1
    How often is this value to be generated? Daily? Every second? If every second can you generate enough unique values to cover the time span - I am not going to do the maths? Do you need UNIQUE or RANDOM? As stated, random will not necessarily produce unique tokens over that period. If you need unique then why not use a simple counter? – NicC Oct 03 '18 at 13:54
  • 1
    @NicC is right. I personally would use the current time and date as part of the string and or random seed. – paulywill Oct 03 '18 at 19:41

3 Answers3

7

There is no built-in UUID function in Rexx. Walmart Labs has open sourced a z/OS based service that generates UUIDs guaranteed until the year 34,000 :)

zUID is a cloud enabled service in the z/OS environment that generates a unique identifier using a specialized patent-pending algorithm. It is guaranteed to generate 100% unique identifiers until the year 34,000 without requiring a database system to manage.

Service returns the UID in 3 different hex formats, plain, guid and ess in plain text format. They are not wrapped in XML or JSON structures.

plain: 32 bytes, 1234567890abcdef1234567890abcdef
ess: 34 bytes,12345678-90abcdef12345678-90abcdef
guid: 36 bytes, 12345678-90ab-cdef-1234-567890abcdef

No authorization is needed for this service.

In addition to being web enabled you can call this routine directly using a CICS LINK command in your COBOL programs. The HTTP interface was designed to make it available for more consumers out side the z/OS environment.

Hogstrom
  • 3,581
  • 2
  • 9
  • 25
  • thank you. I'm just looking only for a function that will do generating a unique ID using REXX . – hotcoder Oct 02 '18 at 08:42
  • i understand. Creating a random string is one part, ensuring it is uniquely identifiable for a specific time period is the more challenging part. – Hogstrom Oct 02 '18 at 12:34
  • @Hogstrom I really found the information in this answer to be hepful. I just can't try this service at my site as we don't have authority to download and install services like these on our own. I'm planning to try this out (along with Hercules emulator) on my local machine. Thanks a lot! – Srinivasan JV Oct 02 '18 at 12:57
0

Are you running your REXX on an z/OS system? If so you can generate unique numbers using the STCKE STORE CLOCK EXTENDED instruction which will be unique for thousands of years when generated on the same system or sysplex with synchronized clocks.

You'll need to crack open the assembler to write an external REXX function.

STCKE    RSECT                                                         
STCKE    AMODE 31                                                      
STCKE    RMODE ANY                                                     
         SAVE  (14,12)                                                 
         LR    R12,R15                                                 
         USING STCKE,R12                                               
         USING EFPL,R1           REXX external function parameter list 
         L     R4,EFPLEVAL                                             
         L     R4,0(R4)          REXX evaluation block                 
         USING EVALBLOCK,R4                                            
         STCKE EVALBLOCK_EVDATA  Store STCKE in the function result area   
         MVC   EVALBLOCK_EVLEN,=F'16' length of result (STCKE)         
         LA    R15,0             RC=0                                  
         RETURN (14,12),RC=(15)                                        
         YREGS                                                         
         IRXEFPL                                                       
         IRXEVALB                                                      
         END     

And make sure you set numeric digits in the REXX code as STCKF is a 16 byte huge number!

/* REXX */            

numeric digits 64     

do 10                 
  raw = stcke()       
  hex = c2x(raw)      
  num = x2d(hex)      
  say hex num         
end
David Crayford
  • 571
  • 1
  • 3
  • 10
  • @SaggingRufus Yes and a fair bit more than 50 years. Going by the Walmart code it will be unique until the year 34,000 when the extended TOD rolls over. Of course, it's only unique on the LPAR or sysplex it runs on so to make it more granular add a string such as the LPAR name or Plex name. That's kind of what UUID generators do on other platforms when the use the MAC address. – David Crayford Nov 20 '18 at 11:51
-1

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.

Srinivasan JV
  • 705
  • 5
  • 12
  • thank you. It is helpful. But the other question is The value will not repeat next 50 years.( generated string) . – hotcoder Oct 01 '18 at 14:30
  • 2
    There is no guarantee these will ever be unique. Its a random number. You could run it twice back to back and get the same result. there is a 1 in 1000 chance you will get the same string. If this needs to be unique over the next 50 years you will need a different solution. – SaggingRufus Oct 01 '18 at 14:33
  • @hotcoder There are no information in the Manual as to how long the numbers will be random. However, the manual says the function would `return a quasi-random nonnegative whole number. The numbers are generated mathematically, using the initial seed, so that as far as possible they appear to be random. Running the program again produces the same sequence; using a different initial seed almost certainly produces a different sequence. If you do not supply a seed, the first time RANDOM is called, an arbitrary seed is used. Hence, your program usually gives different results each time it is run.` – Srinivasan JV Oct 01 '18 at 14:45
  • In our site, we've triggered multiple jobs at the same time & none of the jobs have had same job name (Note: `USERID()` returns the same value, say 'SRINI'. It's `RANDOM()` function's value + `USERID()` which makes the job name unique). – Srinivasan JV Oct 01 '18 at 14:46
  • 1
    @hotcoder this could work, but there is no guarantee it will. All you are doing here is taking 10 random characters and stringing them together. Yes this COULD produce the desired result (if you are lucky), but adversely, if you are unlucky they names will not be unique. – SaggingRufus Oct 01 '18 at 16:46
  • 2
    @SrinivasanJv you can be confident it can produce semi random job names, also even if it did, I am pretty sure all JES systems can handle 2 jobs with the same name (one will just wait until the other is finished before it starts), but if you need something to be unique for the next 50 years, this cannot do that with degree of certainty. Especially when the seed is an arbitrary one. – SaggingRufus Oct 01 '18 at 16:51
  • @SaggingRufus I agree with your point and I'm aware JES systems can handle 2 jobs with same name & last one will wait until the completion of the first job. But, if the job name is unique, they will run simultaneously, as the jobs don't share a common resource. We overcame this problem with code snippet which I've shared in this answer. OP's initial question was something relevant to what I've worked in the past and I thought I would share it in this answer. I indeed agree that code snippet in my answer can't produce unique results for the next 50 years. Thanks for your suggestions! – Srinivasan JV Oct 02 '18 at 12:47
  • 2
    I got a solution by concatenating with time. – hotcoder Oct 03 '18 at 13:02
  • @hotcoder It would be helpful if you can edit the code snippet in the question, with what you've tried. – Srinivasan JV Oct 03 '18 at 13:14
  • @hotcoder So, you accept this as an answer even though it has no relation to your final solution? Nothing in this response ensures that the requirements in your original problem will be met. – Rich Jackson Oct 25 '18 at 10:55