Tuesday, June 23, 2009

(FAQ) Here's a sample program that generates random number in AS/400 RPG ILE

Sample:

D C0Seed S 10I 0 Inz(0)
D C0RndNbr S 8F
D* Random Number Conversion
D RndNbr S 10I 0
D MaxNbr S 10I 0 Inz(9000000)
D MinNbr S 10I 0 Inz(1000000)
C*
C DoU RndNbr >= MinNbr
C*
C CallB 'CEERAN0'
C Parm C0Seed
C Parm C0RndNbr
C Parm *OMIT
C*
C Eval RndNbr = %DecH(C0RndNbr:30:29) * MaxNbr
C EndDo
C*
C Return


1 comment:

  1. So sorry, but it only works in interactive.
    In batch, CEERANO returns (quite) always the same number.

    ReplyDelete