Giovanni's logo Generate a random integer
using Random subprocedure
this means Version 2
power search
blue line
This subprocedure returns a random integer between two user-specified values. A random integer is expecially useful to create a session ID ("handle") for persistent CGI programs.

Click here to see a live example of a CGI program using this subprocedure,
here to display the source of such sample program.
 /copy mysrclib/qrpglesrc,hspecs
 /copy mysrclib/qrpglesrc,hspecsbnd
 * Variables common to all CGIs
 /copy mysrclib/qrpglesrc,prototypeb
 /copy mysrclib/qrpglesrc,usec
 /copy mysrclib/qrpglesrc,variables3
 * Variables required by subprocedure "random"
DMyRandom         S             10u 0
DMyLow            S             10u 0
DMyHigh           S             10u 0
 *          ... etc. ...
 * Asks for a random integer
 *  between 0 and 9, to be returned in variable "MyRandom"
C                   eval      MyLow = 1
C                   eval      MyHigh = 9
C                   eval      MyRandom = random(MyLow:MyHigh)