Tools
Categories

# RANDOM operator

 Reference Number: AA-00482 Last Updated: 2013-09-10 12:33
Version 4.7.1+ required

Operators depend on which version of the mobile application is currently installed on the device. The RANDOM operator is available from version 4.7.1+ and the SET operator from version 4.1.0+.

Go to the Operator Overview to check the availability of other operators. If required, you can re-provision the device to download the latest version.

The RANDOM operator returns a random number (integer or decimal value) between two specified values. By specifying a "c" or "d" for the third argument the result can be continuous (fractions) or discrete (integers only).

## Syntax

__{RANDOM(fromvalue,tovalue,cd)}__

## Examples

Example #1: Random branching

Operators used: RANDOM and SET

Use case: In certain scenarios, it may be useful to randomly determine whether or not a respondent should be asked a set of questions (e.g. for randomised sampling). To achieve this, a survey can be configured to generate a random number, store this number and then direct the respondent to answer a different part of the survey accordingly.

In this example, the number generated is not displayed on the device, but is stored in question 1.4.

Figure 1:

Explanation of above screenshot:

• In Figure 1, the two questions concerning randomisation are 1.3 and 1.4.
• Randomisation (1.3) generates a random integer between 2 and 4 inclusive (i.e. 2, 3 or 4). The "D" (not case sensitive) in the formula stands for Discrete which returns integers (whole numbers) as opposed to C ("Continuous") which returns fractions.
• The SET operator is then used to store the random number in question 1.4 (id 255652).
• The skip branches in 1.4 direct the respondent to different parts of the survey depending on the random number returned.

How to replicate this example:

1. Create a question of Type "Variable" and Variable Type ("Operator").  (1.3 above, see Figure 2 below)

a. Press "Next" to insert the formula as the default value using the question idâ€™s and the parameters you need, e.g. __{SET(255652,__{RANDOM(2,4,D)}__)}__. (See Figure 3 below)

2.     Create a question of Type "Variable" and Variable Type "Numeric" and select "Finish". (1.4 above, see Figure 4 below)

3. Add branches or skip logic to decide what action happens dependent on which number is returned.

Figure 2: Creating variable question (1.3).

Figure 3: Formula inserted in the Default Value of Operator question (1.3).

Figure 4: Creating variable question (1.4).

Other common use cases include:

• Randomly assigning a participant for a Randomised Control Trial (RCT) into a follow-up arm/cohort.
• Random generation of access codes.