[[random()]]
SoSci Survey
Translations of this page:
 

Table of Contents

random()

int random(int min, int max)

The function random() returns a whole number between min and max. It is suitable for random draws with replacement. Examples of its use as part of a random draw can be found in the chapter Randomization.

  • min
    The smallest number allowed
  • max
    The largest number allowed

Note: If a random draw without replacement is used in an experiment, then different sizes of experimental groups are inevitable. SoSci Survey offers urns for random draws with replacement.

Return Value

A whole number between min and max

min ≤ return value ≤ max

Example

In the following example, a number between 1 and 3 is drawn and the participant is shown one of the text elements “stimulus1” to “stimulus3” corresponding to the number. The function put() is used to save the drawn number in the data record.

// Draw a random number
$stim = random(1, 3);
// Save the result of the draw in the data record
put('IV01_01', $stim);
// Display stimulus
if ($version == 1) {
  text('stimulus1');
} elseif ($version == 2) {
  text('stimulus2');
} else {
  text('stimulus3');
}
en/create/functions/random.txt · Last modified: 13.01.2015 16:29 by alexander.ritter
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki