MITHARG
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Generating a Random number on an iSeries in CL

Go down

Generating a Random number on an iSeries in CL Empty Generating a Random number on an iSeries in CL

Post  kasthuri Sun Jan 27, 2013 2:32 pm

Neither CLP nor RPG has a Pseudo Random Number generator built in, so we have to kludge it to get it to work. You can link the QLEMF C library and use the CERNAN0 api .

The other way is to use the QSH shell to do it. But this method generates a random number between 0 - 32767 inside the QSH shell env and then stores the result in a DTAARA so that the calling program can access the value, as there in no native way to return vars from QSH environment

Firt creare a dataarea
CRTDTAAARA MyRand *CHAR 5

Then use the following CL source to get the random from Qshell

PGM
DCL &CMD *CHAR 40
DCL &RANDNO *CHAR 5
CHGVAR VAR(&CMD) VALUE('print $RANDOM|datarea -lw MYRAND')
QSH CMD(&CMD)
RTVDTAARA DTAARA(MYRAND) RTNVAR(&RANDNO)
ENDPGM

kasthuri

Posts : 212
Join date : 2013-01-27

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum