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.


images/download/attachments/91131724/image2023-1-23_13-51-48-version-1-modificationdate-1674478308121-api-v2.png

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:

images/download/attachments/91131724/image2023-1-23_13-52-23-version-1-modificationdate-1674478344044-api-v2.png

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:

  • A Set value event action attaches the return value of a Random text token value resolver to the possibly already existing text value of the variable token via the Concat strings value resolver, where the possibly preceding minus sign is removed from the text value resolved by the concatenated Replace text value resolver.

  • Subsequently, an If then else event action checks whether the length (length) of the text in the variable token already has sufficient length, i.e. whether its length is greater than or equal to the value of the loop variable $length. According to the parameterization for the Resolver for entities in the loop header, this variable contains the value 50.

  • If the token has reached or exceeded the desired length, the loop is to be terminated after the action block has been processed. A Set value event action assigns the value of the $length variable to the $index variable for this purpose.

  • Then – before the loop is exited – the text length is adjusted exactly to the required length (here: 50 characters) by limiting the text built up in the variable token to the number of characters specified in the variable $length via the Substring value resolver.

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.

images/download/attachments/91131724/image2023-1-23_13-55-45-version-1-modificationdate-1674478545520-api-v2.png images/download/attachments/91131724/image2023-1-23_13-57-8-version-1-modificationdate-1674478628288-api-v2.png