RPGLE Generate Random Numbers – Using CEERAN0 API

ILE RPG has no native random number generator. An ILE-bindable API, CEERAN0, tin flame endure invoked from ILE RPG programs to generate such numbers.

CEERAN0 takes every minute input an integer seed, which it updates each fourth dimension to avoid repetitions inwards the random number sequence, in addition to outputs a double precision random number (if given 0 every minute a seed, CEERAN0 volition generate a random number based on the electrical flow arrangement time).

The programme sample inwards this document illustrates how to make random numbers.

RPGLE Sample Source Code for Random Number Generation

H DFTACTGRP(*NO) ACTGRP('QILE')                                                                                   d CEERAN0         PR                                     d seed                          10I 0                    d ranno                          8F                      d fc                            12A   options(*omit)                                                              d highno          sec             10I 0 Inz(9000000)       d lowno           sec             10I 0 Inz(1000000)       d seed            sec             10I 0 inz(0)             d rand            sec              8F                      d arrive at           sec             10I 0                    d number          sec             10I 0                                                                              /free                                                        arrive at = (highno - lowno) + 1;                            CEERAN0( seed : rand : *omit );                          number = %int(rand * range) + lowno;                     dsply result;                                            return;                                              /end-free         

Recommended Reading

Sumber http://www.mysamplecode.com/