Random text token
See also: Random long value
Value resolver – Abstract
Purpose: Returns a random text token (String) as a hexadecimal representation of a random Long value.
The Random text token value resolver returns a random text token (String).
The generated text token is the base36 image of a random Long value, i.e., on the server side, the hexadecimal representation of a 64-bit integer whose most significant bit defines the sign.
For the arbitrarily named text token in the return value (String) this means specifically:
The string starts with a minus sign in approx. 50% of the cases. For positive values, no plus sign is prefixed.
Since the base36 digit sequence does not use 'leading zeros' for the absolute amount, a base36 digit (definition as a regular expression: [0-9a-z]) must appear as the first character after the prefixed minus, if any.
Depending on the absolute value of the internally 'cubed' Long value, this is followed by up to 12 further base36 digits ([0-9a-z]).
The length of the returned text token can theoretically be between 1 and 14 characters due to the value range for Long, where 14 characters is only reached with the preceding minus.
Even if the return value produces strings of 10 or more characters with high probablity, the random occurrence of shorter strings at runtime should not be neglected across the board.
►IMPORTANT◄ In a Client workflow, only the lowest 52 bits of the random Long value are processed. The higher value bits are ignored or truncated. This also includes the sign bit (No. 64)! The value range in the Client workflow is therefore limited to integers in the interval [0;2^52[. A text token generated via a Client workflow therefore never starts with a minus sign and also only reaches a maximum length of 11 characters..
►NOTE◄ If a minimum text length (>1 character) is absolutely necessary for the random text, this must be systematically enforced by further measures. The examples (below) demonstrate with two differently elaborate approaches how this can be achieved.
Configuration
The Random text token value resolver ignores the input value and does not use any parameters.
Examples
Random text token with exactly 14 characters
The following configuration assigns a random sequence of digits and lowercase letters with a length of 14 characters to the variable token:
The value configuration on the right side of the Set value event action defines the assigned text value in three steps:
The first substring within the Concat strings value resolver is 'cubed' with the Random text token value resolver.
The Concat strings value resolver attaches a statically defined string of 13 zeros as the second substring.
The concatenated Substring value resolver returns only the first 14 characters of the concatenated string.
The attached zeros compensate for the fact that the Random text token value resolver can provide less than 14 characters.
►NOTE◄ Because the Random text token value resolver reaches a text length only with return values that start with a minus sign, the 'prepared' token with this configuration always ends with the character '0' if it does not start with a minus sign.
Random text token with arbitrary length
In an event handler, a random text token with 50 characters is to be reliably generated and assigned to the variable token.
The configuration shown on the right for a For each loop event action, accesses the Random text token value resolver up to 50 times to assign a sufficiently long string to the token variable by concatenation. ►NOTE◄ The variable token should be assigned 'No value' ($null) or an empty string ('') before executing the loop to be on the safe side. The following steps are executed in the action block for iteration:
►NOTE◄ With multiple access to the $length variable automatically populated within the loop, the token length can be easily adjusted as needed by adjusting the Resolver for entities parameter in the loop header. |
|