How can I randomly choose which of two questions to display?

Hi everyone,
I got a problem and couldn't fix it. I have two different questions and i want to randomize the two questions, that means I want one question(either of the two) randomly picked and asked at a time. I can randomize an option but i cant randomize questions.

Can you help me?

Thank you
YoYo

You may want to implement this strategy for the situation: Develop 3 forms, one for the randomization (say Form A), the other two are the main questions that you want to administor randomly (say Form B & C). Forms B & C are hidden so that enumerators don't see them in the app. They see Form A instead. From From A, depending on the random value, B or C will be displayed.

What @Trung describes is not possible in ODK and does not sound convenient for a small number of questions to randomize. The recommended strategy is similar but within a single form.

You can create groups for each order that you might want to display to the user, generate a random number, and use that random number to pick one of the orderings. Here is a form that shows the strategy with two questions. Note that a dynamic default is used to ensure that the random value is stable across multiple opens of the same form instance.

There has been some discussion of adding a dedicated feature for this purpose at Randomizing Lists or Questions within Groups.

2 Likes

Thanks @LN , your strategy is perfect for a small number of questions to randomize.

1 Like

One potential issue, though: if we use default with random() like that, we might have the random number changed if user opened a saved incomplete version.

The behavior you describe is what would happen if we defined a calculation instead of a default. Please read the documentation about dynamic defaults that I linked to for more details.

3 Likes

Thanks @LN . I missed the word once in this sentence "Dynamic defaults as described in this section are evaluated once on record creation."

1 Like

Dear LN,

Thank you very much for your response. yeah it works, but i want one question randomly picked and show once at a time. the example you give me is it randomize the questions only, but what i want is if question A is asked i want question B to be hidden. if question B is asked i want question A to be hidden. Can you help me please?

Try something like this:

randomquestion.xlsx (8.5 KB)

Basically, generate a random number using random(), and then use this value in relevant expressions on each question to determine whether to display that question or not. If the ranges are mutually exclusive - eg 2 questions, with <0.5 and >=0.5 - then only one question will get displayed. You can optionally adjust the ranges to change the weight/frequency each question appears...

4 Likes