See also: Random text token
Value resolver – Abstract
Purpose: Returns an integer signed 64-bit (Long) pseudo random number on the server side.
Tooltip
Usage: The value reolver returns a signed 64-bit (Long) integer pseudorandom number on each call. The input value is ignored.
Note: To obtain random numbers in a certain range of values, the modulo operator (%) can be used in a concatenated Calculate value value resolver, for example.
Example: Calculation expression abs(random%limit) returns random numbers in the range {0, ..., limit-1} if random is a Random long value.
Warning: In the client context, only the lowest 52 of the 64 bits are considered, so only integers ≥0 (from the interval [0;2^52[)are returned.
The Random long value resolver returns a signed 64-bit (Long) integer pseudorandom number on the server side.
►IMPORTANT◄ In a Client workflow, the Random long value resolver returns only the lowest 52 bits of the random Long value for technical reasons. 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[, while on the server side the 64bit value range spans approximately symmetrically around 0.
Configuration
The value resolver ignores the input value and does not use any parameters.
Example
An event handling makes a random selection from a number of options. The options for the selection are determined 'dynamically' at runtime via a Search (Event action). The number of options can vary depending on the basic data and the search criteria.
All options qualified by the Search (Event action) are considered equally in the random selection, i.e. selected with the same degree of probability.
In the specific example, an event handling should make a random single selection from a subset of instances for a custom entity type (see Custom type definition) ‘Aircraft’ (Aircraft), whose suitability for a specific use is checked by Restrictions within the Search.
Configuration:
The screenshot on the right shows an overview of the configuration of event handling, which determines a list of qualified 'candidates', makes a random selection and communicates the decision via a notification:
First, a Search (Event action) is executed to determine suitable candidates from all instances for a custom entity type ‘Aircraft’ for which read access exists in the execution context. The list of these candidates for the random selection is written to the Variable acft_subset as a ‘result list’.
All further steps take place in the action block of an Execute with event action, which defines the list of candidates in the Variable acft_subset as a temporary reference object using the Object resolver parameter:
In the first step, the return value of the Random long value resolver is used to make a random selection from the candidates in the Variable acft_subset. Within a Set value event action, the index number of the list value to be selected is ‘rolled’ and assigned to the randomPick variable as an Integer value:
Within the value resolver chain for the value to be assigned (right), the number of candidates is first determined using the Object property resolver from the length field of the list given as the reference object. In the Calculate value resolver, the input value can be addressed here by concatenation via the ‘Variable name’ input. The Random long value resolver is also included via the configuration for the Variable name random.
The calculation expression abs(random%input)uses this to determine an index value in the permitted range. The index of the list begins with the start value 0, so that the maximum permissible index value of a list is length-1. The remainder of an integer division (using the modulo operator %) by the number of list values (length = input) therefore represents the desired value range if the sign for negative values is ‘eliminated’ using the abs()function.
An integer is taken from the calculation result with the data type ‘Unit number’ (UnitNumber) by assigning it to the Variable randomPick (left) with the Type integer.
Finally, the result of the random selection is revealed by a Show alert event action (see below).
|
|
The screenshot on the right shows the configuration for the Show alert event action, which is still executed in the context of the Execute with event action with the list of candidates as the reference object:
The List item resolver refers to the candidate list (reference object) and uses the Mode 'Get first' to determine the list entry to be returned via the Offset. The name of the Variable randomPick is entered in the Offset parameter, the return value of which specifies the ‘checked’ index of the list item at runtime.
The concatenated Store value as variable resolver stores the randomly selected ‘Aircraft’ instance in another Variable pickedAcft, which can be accessed by subsequent event actions.
The concatenated Object property resolver reads the registration field from the ‘Aircraft’ instance, the value of which is used to identify the selection in the Message.
Runtime example:
►NOTE◄ The ‘cloze text’ in the Title for the Show alert event action can be executed in multiple languages by using a Value from localization resolver in conjunction with a language management entry that provides a ({0}) parameter for the number of options.
|
|