PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Generating a Random number on an iSeries in CL

View previous topic View next topic Go down

Generating a Random number on an iSeries in CL

Post  maran on Thu Jul 28, 2011 12:49 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

avatar
maran
Admin

Posts : 442
Join date : 2009-07-24

View user profile http://pmsinformationsystem.forumotion.net

Back to top Go down

View previous topic View next topic Back to top


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