On 03-Jul-2017 21:30 -0600, Booth Martin wrote:
Random generating a 16-digit number:
Whether the number must be a "counting number" [i.e. positive integer
value] or inclusive of zero is unstated; be sure to verify whatever
interface gives the desired effect.
An easy task in Rexx. Or so I thought. I can not figure out how to
return that value to the calling program. QREXQ seemed the right way
but I can not make it happen.[…]
Specifically for using REXX; though IMO, not as easy, as compared to
using SQL:
If the biggest value requirement were for a smaller number, perhaps
merely 15-digits as a whole number, then a *DEC decimal Data Area
(DTAARA) could hold the return-value for a caller. Or as an
alternative, perhaps storing part of the whole number precision as
digits _after_ the decimal point, which, as Packed BCD, the caller can
[re]assign an alternative Precision and Scale to the data; i.e. maximum
for the DtaAra is DEC(24:9).
Or, a *DTAARA could still be used for the full 16-digits, but having
used a *CHAR character Data Area, such that the digits would be stored
as character, which, can appear as effective Zoned BCD from the
perspective of the caller, again irrespective precision and scale used
in the called program; e.g.:
/* REXX_RANNO generates a 16-digit value */
/* stored into *DTAARA QTEMP/REXX_RANNO */
numeric digits 32
"dltdtaara dtaara(QTEMP/REXX_RANNO)"
"crtdtaara dtaara(QTEMP/REXX_RANNO) TYPE(*char) len(16)"
rn=""
do i = 1 to 4 /* four, 4-digit numbers concatenated */
rn = rn || rn4dig()
end
/* cannot use &RN below; value perceived numeric CPD0095 */
/* chgdtaara dtaara(qtemp/rexx_ranno) value(&rn)" //Ugh! */
"chgdtaara dtaara(qtemp/rexx_ranno) value('"rn"')"
debug: "dspdtaara qtemp/rexx_ranno output(*) outfmt(*char)"
exit
/* Function: rn4dig() returns a 4-digit */
/* random number as a 4-character string */
rn4dig: procedure
return right( '0000' || random( 9999 ) , 4 )
In SQL, for a similar [character] effect:
values (digits(dec(rand(), 16, 16)))
As an Amazon Associate we earn from qualifying purchases.