Giovanni's logo Generate a random string
using randomString subprocedure
this means Version 2
index
M
power search
blue line
Subprocedure randomString returns a string up to 1024 random characters. The caller controls the number of characters returned, the contents and case of the first character, and the contents and case of the remaining characters.
This procedure can be used for assigning temporary names for user spaces, stream files, file members, etc.

Parameters:

  • Number of characters to return (0 - 1024)
    If 0, a null string is returned.
    If > 1024, 1024 characters are returned.
  • First character (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)
  • Remaining characters (if not passed, defaults to *mixedDigit)
    • same choices as first character
  • UpperChars - characters that are "upper case")
    • If not passed or has length = 0, defaults to 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  • LowerChars - characters that are "lower case")
    • If not passed or has length = 0, defaults to 'abcdefghijklmnopqrstuvwzyz'
  • DigitChars - characters that are "digits")
    • If not passed or has length = 0, defaults to '0123456789'
For more information, see CGIDEV2/QRPGLESRC member XXXRANDOM.

Example:

D UsrSpcName      s             10
C                   eval      usrSpcName = RandomString(
C                             10:'*UpperLetter':'*UpperDigit')