How to randomize items at Limesurvey

Limesurvey provides various randomization features at different levels and you should make use of it for various reasons. Especially at market research surveys randomizing items is a must-have feature in order to collect data properly. Another use case is A/B testing where you randomly show version A or B or a question for comparing the outcome of e.g. different question texts.
There are some more reasons we have outlined below when introducing the different Limesurvey randomization features.

Randomizing the order of answers/items

Research shows that people tend to pick one of the first answer options and often do not even check all available options. This can result in misleading survey results. So what can we do?
Well, that is rather simple: Most Limesurvey question types provide a setting Random order which can be found at the Display section below the General options. Simply turn it on and that’s it:

Limesurvey "Random order" setting
Limesurvey “Random order” setting

Want to check how this looks like at a real survey? Then check out the test survey we created for you.

Randomly show 1 of X questions (can be used for A/B testing)

There already is a special blog post dealing with this topic so we will just link to it: https://survey-consulting.com/how-to-randomly-show-1-of-x-questions-at-a-limesurvey-survey/

You can check this randomization feature at this test survey.

For creating an A/B test the approach is the same as explained at the example linked above. Simply created two copies of the same question and set conditions based on the random number to either show question A or question B.

Randomly show questions on page

Besides randomizing items within a question you can also randomize the questions displayed on a single page or within the whole survey.
For setting this up there is an option Randomization group name at the Logic section when editing a question. Enter the same randomization group name at all questions which should show up in random order:

Adding a randomization group name to a question
Adding a randomization group name to a question

So if you added rand1 as randomization group name to questions Q1, Q2 and Q3 these will show up in random order when loading the survey like Q3, Q2, Q1 or Q2, Q1, Q3.

We have provided a sample survey at this link.

Randomly show question groups or survey pages

The group by group display mode is the survey format used at most surveys. This means that you put questions dealing with the same topic into the same question group like questions asking for demographic details. If your survey deals with e.g. tech companies you could then have another set of questions at the follow up question group dealing with question related to Amazon, then have another question group asking details for tech company 1, another one for tech company 2 and so on…

Since the drop off rate would usually lead to receiving many opinions about Amazon but just some very few responses related to the tech companies listed towards the end of the survey, your data will be less reliable when comparing the response details for different companies.
To work around that you could simply show the survey groups related to the different tech companies in random order. This can be achieved by entering the same Randomization group when editing a question group:

Adding a randomization group title
Adding a randomization group title

By adding randomizecompanies to all your to be rated companies these pages will show up in random order within the survey.

We have set up an example with Amazon, Google and Facebook for you showing the question groups for rating these companies in random order.

Randomly show 1 of X follow up surveys

Sometimes users are redirected to a certain follow up survey once they have completed the main survey. In certain cases there is not just one survey but you may want to pick 1 of X surveys randomly and redirect users to them.
This is doable by following the approach of randomly showing a question. You create a question of type equation with code randnumber and as question text you simply add:

{if(is_empty(randnumber.NAOK), rand(1,3), randnumber.NAOK)}

This will create a random number between 1 and 3 if there was no such random number created so far. The newly created number can then be used for defining which URL to call.
You can have another question of type equation using question code redirecturl and based on the random number you can define URLs for 3 different surveys.

{if(randnumber.NAOK == 1, "https://survey.mydomain.com/index.php/111111", 
if(randnumber.NAOK == 2, "https://survey.mydomain.com/index.php/222222", 
https://survey.mydomain.com/index.php/333333"))}

At the survey settings you can optionally enable Automatically call end URL and at the End URL text field of the setting just add {redirecturl.NAOK}. Depending on the randomly created number and the end URL set for it Limesurvey will call one of the 3 surveys randomly.

We added the random redirect to the sample survey created for the Randomly redirect or show 1 of X questionsuse case. Click here to start that survey and you should then see different end URLs at the final “Thank you” page pointing to different surveys.

Sample survey showing all randomization features

All the different features outlined above can be tested at this Limesurvey randomization sample survey.

How to place a certain option at the end of a list with randomized answers at Limesurvey survey

Randomizing answer items is an often used approach at scientific surveys and market research. At Limesurvey this can easily be done. Just go to the advanced question settings of a certain question and then set “Random order” to “Randomize on each page load“.
But often such a list contains an option like “Don’t know” or “None of these” or similar. Such an option may appear in the middle of the list of answers if they are randomized and that looks confusing to the user.

In order to place a certain answer item at the bottom of a randomized list, add the following JavaScript code at your question text, using the source code mode of the editor:

Source code mode:
Source code mode of integrated Limesurvey editor

Code:

<script type='text/javascript'> 
/* Place option 5 at the end of the randomized list */
$(document).ready(function() {
var move_element="5";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
}); 
</script>

This script snippet will move answer item 5 to the end of the randomized list. “5” is the answer code of the to be moved item.

You want to re-order the “other” option? No problem, we have explained this at How to re-order the “other” option at a Limesurvey survey.

How to randomly show 1 of X questions at a Limesurvey survey

Limesurvey offers various randomization features. One common randomization use case is showing different versions of a question at a Limesurvey survey. To do so, you need to randomly show one of the X question versions to the user so the first step would be to generate a random number between 1-X. For this we can use the powerful Limesurvey Expression Manager which is available since release 1.92.

The new question type “equation” can be used to store the result of the random function. So create an “equation” question with question code “randnumber” and the following content at the question text field, which will generate a random number between 1 and 2:
{if(is_empty(randnumber.NAOK),rand(1,2),randnumber.NAOK)}

The whole code basically means that the system should first check if the rand variable was already populated. If it is still empty, a random number between 1 and 2 is created. Else, the already created number is kept and no new random number gets created.

If you want to hide the question from the user, set “Always hide this question” to “yes” at the advanced question settings.
Now we have a question that will be filled with either “1” or “2”, we can use conditions at following questions to show version A or version B of a question. For this you can use the Limesurvey condition manager and set a condition based on a constant value of 1 or 2 for the equation question. Alternatively you can use the “relevance” field to define when a question should be shown. The appropriate relevance reads:
((randnumber.NAOK==”1″))

…and for the second question:
((randnumber.NAOK==”2″))

Don’t forget to check if you set up everything correctly by having a look at the survey logic file.

…and if this still sounds too tricky, we can set up the survey for you.