assistance-engine/docs/developer.avapframework.com/appendices_2.md

1.3 KiB

randomString()

The randomString() command generates a random string based on a specified pattern and stores it in a target variable. It is especially useful when random strings are needed to conform to a specific format, such as passwords or identifiers.

Parameters

  • Pattern Type: var Description: A regular expression (regex) pattern that defines the characters and structure of the string to be generated. It can be a direct value or a variable containing the pattern. For example, [a-zA-Z0-9] will generate a string that includes uppercase letters, lowercase letters, and numbers.
  • Length Type: var Description: An integer value specifying the length of the random string to be generated. It can be a direct value or a variable containing the desired length. This value determines how many characters the resulting string will have.
  • TargetVariable Type: var Description: The variable where the generated string will be stored. This variable should be used later in the program. Unlike the other parameters, this must be a variable and not a direct value.

Usage Example

// Direct call with values:
            randomString('[a-zA-Z0-9]', 8, generatedPassword)

            // Call using variables:
            pattern = '[a-zA-Z0-9]'
            length = 8
            randomString(pattern, length, generatedPassword)