Skip to main content development
   toolset
 
  Easy400   |       iSeries home
Public-Source
 
Introduction
Tutorial
Examples
FAQ
Index
Download
 
 

 
2.9 - Random numbers and strings


  •  QRandom  - Generate a random integer
    Input parameters:
    1. low end of range (decimal)
    2. high end of range (decimal)
    Returned value:
    • generated random integer (decimal)

    Example:
                ...         ...         ...
           SPECIAL-NAMES.
                 copy CPYSPCNAME of CGICBLDEV2-QCBLLESRC.
                ...         ...         ...
          * Variables for QRandom procedure
               05     mylow            PIC  S9(9) comp-4 value 1.
               05     myhigh           PIC  S9(9) comp-4 value 1000.
               05     myrandom         PIC  S9(9) comp-4.
                ...         ...         ...
          * Retrieve a random integer
               call 'QRANDOM' using mylow myhigh
                              returning into myrandom.
    

    See also program RANDOMINT.

  •  QRandomString  - Generate a random string
    Returns a random string, 1024 characters in length.
    Input parameters:
    1. Number of characters to return (0 - 1024), decimal
    2. (optional) First character (char 12) (if not passed, defaults to *mixedDigit)
      • *upperLetter (upper case letter only)
      • *lowerLetter (lower case letter only)
      • *mixedLetter (upper or lower case letter only)
      • *upperDigit (upper case letter or digit)
      • *lowerDigit (lower case letter or digit)
      • *mixedDigit (upper or lower case letter or digit)
      • *digit (digit only)
    3. (optional) Remaining characters (char 12)
      (if not passed, defaults to *mixedDigit)
      • same choices as first character
    4. (optional) characters that are "upper case" (char 100)
      (if not passed defaults to 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    5. (optional) characters that are "lower case" (char 100)
      (if not passed defaults to 'abcdefghijklmnopqrstuvwzyz')
    6. (optional) characters that are "digits" (char 100)
      (if not passed defaults to '0123456789')

    Example:
                ...         ...         ...
           SPECIAL-NAMES.
                 copy CPYSPCNAME of CGICBLDEV2-QCBLLESRC.
                ...         ...         ...
          * Variables for QRandomString procedure
               05     randomString        PIC  X(1024).
               05     stringLen           PIC  S9(9) comp-4.
               05     firstChar           PIC  X(12).
               05     remainChar          PIC  X(12).
                ...         ...         ...
          * Generate a random string, length=10,
          * first char= uppercase letter remanining chars = digit
          * remanining chars = digit
               compute stringLen = 10
               move '*upperletter' to firstChar
               move '*digit' to remainChar
               call 'QRANDOMSTRING' using
                                    stringLen
                                    firstChar
                                    remainChar
                                    returning randomString.
    

    See also program RANDOMSTRG.




  •     Contact