Updated RxRandom External Rexx Function (in C)

By | September 3, 2013

The Rexx external function RXRANDOM I wrote about before is not very compatible with the IBM provided (and standard Rexx) RANDOM internal function. The one I wrote initially took no arguments, and so did not demonstrate how to handle arguments, whereas the built-in function takes min, max and seed arguments. I can handle the min & max arguments, but not the seed since I am obtaining the random number from the hardware using ICSF, not using a pseud0-random number generator.

Arguments are passed in an array with an address pointer and a length for each. Running EDCDSECT against IRXARGTB generates this for it:

struct argtable_entry {                                                        
  void          *argtable_argstring_ptr;    /* Address of the argument string */
  int            argtable_argstring_length; /* Length of the argument string  */
  double         argtable_next;             /* Next ARGTABLE entry            */
  };

which is pretty good, though argtable_next is not really a “double”. The array is anchored from the efpl that is passed to the program, so with

struct argtable_entry * argtp;

and

argtp      = (struct argtable_entry *) efpl.efplarg;

we have the first argument addressed by argtp->argtable_argstring_ptr and its length in argtp->argtable_argstring_length. Then the next argument in the array is

argtp = (struct argtable_entry *) &argtp->argtable_next;

(Casting to override the bogus “double”.)

A ptr value of 0xffffffff indicates we have reached the end of the argument array.

RXRANDOM could be invoked with zero, one or two arguments.

>>--RXRANDOM(--------------------------------------)
               +-max----------------------------|   
               +----min,------------------------+   
                  +-,----+  +-max-+

The default for min is 0 and max is 999, so RxRandom() should give a number between 0 and 999, inclusive. RxRandom(100) would be 0 to 100, RxRandom(-5,5) would be -5 to +5. The built-in RANDOM function doesn’t handle negative numbers, not sure why. Since each parameter should be an unedited numeral, I’ll just use sscanf() for now to parse it, though better error detection might be appropriate.

Here is the source: rxrandom.c

Refer to the earlier post to find the JCL to generate the C headers for the Rexx control blocks and for the JCL to compile the program.

Also see the later post which uses Metal C instead of SPC.

Leave a Reply

Your email address will not be published. Required fields are marked *