Advanced randomization using custom scripting

How can I set up my own question randomization?

You can use custom scripting to set up custom randomization. An explanation of the script and example script is below.

  1. Click on
    • Login »  Surveys »  Edit
  2. Set up the survey with all of the questions.
  3. In our example, we have 9 questions, numbered Q1 through Q9. Q9 is the last question in the survey. We want to randomize questions Q3 through Q8.
  4. Hover over Q2 to bring up the fly-out menu on the ride side of the screen. Click Page Break to add a page break before the randomization script you will be entering.
  5. Click the Add Question button just above Q3.
  6. Select Custom Script from the Advanced Question Types.
  7. Enter the Randomization script as shown below. The first example is basic randomization. The second example includes script for showing a subset of questions from a set of questions to be randomized (such as showing only 3 of a set of 6 questions randomly). The third example includes script for block randomization.
  8. Check the boxes for Logic Includes Branching and Enable Auto-submit. Note: if you do not enable auto-submit, respondents will see a blank page where the custom script question appears. By enabling auto-submit, this question will automatically move forward, reducing confusion for the respondent.
  9. Click Save.
  10. Create Default Branching logic for each question in the randomization group to branch to a block termination question. In this example, the last question in the survey is the branch termination question, Q9. In any scenario, the question immediately following the group of questions to be randomized should be the block termination question.
including branching for individual answers in select one or select many questions will confuse the script and will cause the custom script to execute incorrectly. Only apply Default Branching for any question involved in the randomization script.

The script for randomization is as below:
#set($ary = ["Q3", "Q4", "Q5", "Q6","Q7","Q8"])
#set($ary = $survey.randomizeList($ary))

#foreach( $val in $ary)
 $survey.branchTo("$val")
#end
In the above script, in the first statement, questions Q3, Q4, Q5, Q6, Q7 and Q8 are added to a list and randomized in the second statement. Once randomized, the survey will display each question randomly.
Randomization script to randomly select 3 questions from a pool of 6 questions (N out of M)

The script for showing N out of M question randomly is shown below:

#set($ary = ["Q3", "Q4", "Q5", "Q6","Q7","Q8"])
#set($ary = $survey.randomizeList($ary, 3))

#foreach( $val in $ary)
 $survey.branchTo("$val")
#end
In the above script, questions Q3, Q4, Q5, Q6, Q7 and Q8 are added to a list and randomized. However, only 3 of the questions will be shown to any single respondent. The set of 3 questions will be randomly selected and shown.
Script for block randomization

Block randomization allows us to group questions together and then randomly display the groups of questions to the respondent. In our example, we want to split the 6 questions into groups of 2 questions. Respondent A might see the groups in this order: block 3, block 1, block 2; Respondent B might see the groups in this order: block 1, block 3, block 2; etc.

The same type of logic is used for randomizing entire blocks of questions. We will split up the 6 questions into 3 blocks of 2 questions each (block 1 = Q3 and Q4; block 2 = Q5 and Q6; block 3 = Q7 and Q8). To set this up in the script, we will only add the first question from each block to the script. We then need to go into the survey and apply Default Branching for the last question of each block (in this example, Q4, Q6, and Q8) to the block termination question (in our example, Q9). Note: just as in the previous examples, branching for each answer does not need to be set, only the default branching option needs to be set for this to work.

#set($ary = ["Q3", "Q5", "Q7"])
#set($ary = $survey.randomizeList($ary))

#foreach( $val in $ary)
 $survey.branchTo("$val")
#end
In the above script, questions Q3, Q4, Q5, Q6, Q7 and Q8 are added to a list and randomized. However, only 3 of the questions will be shown to any single respondent. The set of 3 questions will be randomly selected and shown.
License and Access Options

This feature/tools described here are available with the following license(s) :

Team Edition

Unlimited Surveys, Questions, Responses

Advanced Toolset and Features

No Long Term Commitment