[[random()]]
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
en:create:functions:random [10.04.2016 10:20] – [Drawing with Replacement] adminen:create:functions:random [29.05.2018 10:33] – fixed typo cseifert
Line 8: Line 8:
   * //max//\\ The largest 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 [[:en:create:random_urns|urns]] for random draws with replacement. +**Note:** Although one could create an experimental randomization via ''random()'', we strongly recommend using a [[:en:create:questions:random]]. For more information about randomization an experimental groups see [[:en:create:randomization]].
- +
-**Note:​** See [[:en:create:randomization]] for the application of random draws.+
  
  
Line 18: Line 16:
  
 //min// ≤ return value ≤ //max// //min// ≤ return value ≤ //max//
- 
- 
-==== Drawing with Replacement ==== 
- 
-The PHP functions ''[[:en:create:functions:random|random()]]'' and ''[[:en:create:functions:random_p|random_p()]]'' (for weighted random draws) randomly draw with replacement. An unrestricted random draw "with replacement" is comparable to throwing a die. As a rule, group sizes vary greatly here and this can be problematic for the analysis. 
- 
-**Note:** When drawing with replacement, it is crucial to ensure that the random number is saved in the data record. To do this, use an [[:​en:​create:​questions:​internal|internal variable]] and the function ''[[:en:create:functions:put|put()]]''. 
- 
-  - Add a new question in the **List of Questions** using the type "Internal Variables" (e.g. with ID ''IV01'') 
-  - Add a variable (item) in this question with the description, as an example, "random number". According to the **Variables List**, this variable's ID is ''IV01_01''. 
-  - [[:en:create:php|PHP code]] is used to carry out the actual random draw. 
- 
-<code php> 
-$number = random(1,4);  // rolls a number between 1 and 4 
-put('IV01_01', $number);  // saves the number in IV01_01 
-</code> 
- 
- 
-===== 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 ''[[:en:create:functions:put|put()]]'' is used to save the drawn number in the data record. 
- 
-<code php> 
-// 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'); 
-} 
-</code> 
en/create/functions/random.txt · Last modified: 14.03.2022 12:31 by walliser
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki