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

**URL:** <https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178>\
**Category:** Support\
**Tags:** form-design\
**Created:** [January 25, 2021, 7:04pm UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178 "2021-01-25T19:04:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![YO](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/y/3ab097/32.png) [@YO](https://forum.getodk.org/u/YO)\
**Post date:** [January 25, 2021, 7:04pm UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/1 "2021-01-25T19:04:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trung](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/trung/32/10396_2.png) [@Trung](https://forum.getodk.org/u/Trung)\
**Post date:** [January 26, 2021, 4:21am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/2 "2021-01-26T04:21:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [January 26, 2021, 5:21am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/3 "2021-01-26T05:21:43Z")

</div>

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](https://docs.google.com/spreadsheets/d/1xjiXicYmTtKDlwaApOXifB2r9YEOm8yEtzREHuEyXZk/edit#gid=0) is a form that shows the strategy with two questions. Note that a [dynamic default](https://docs.getodk.org/form-logic/#dynamic-defaults) 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](https://forum.getodk.org/t/randomizing-lists-or-questions-within-groups/6860).

---

<div class="post-metadata">

**Author:** ![Trung](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/trung/32/10396_2.png) [@Trung](https://forum.getodk.org/u/Trung)\
**Post date:** [January 26, 2021, 5:28am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/4 "2021-01-26T05:28:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trung](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/trung/32/10396_2.png) [@Trung](https://forum.getodk.org/u/Trung)\
**Post date:** [January 26, 2021, 5:34am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/5 "2021-01-26T05:34:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [January 26, 2021, 5:42am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/6 "2021-01-26T05:42:49Z")

</div>

> [@Trung](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Trung](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/trung/32/10396_2.png) [@Trung](https://forum.getodk.org/u/Trung)\
**Post date:** [January 27, 2021, 3:26am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/7 "2021-01-27T03:26:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![YO](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/y/3ab097/32.png) [@YO](https://forum.getodk.org/u/YO)\
**Post date:** [January 30, 2021, 7:54am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/8 "2021-01-30T07:54:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Xiphware](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/xiphware/32/2587_2.png) [@Xiphware](https://forum.getodk.org/u/Xiphware)\
**Post date:** [January 30, 2021, 9:11am UTC](https://forum.getodk.org/t/how-can-i-randomly-choose-which-of-two-questions-to-display/32178/9 "2021-01-30T09:11:09Z")

</div>

> [@YO](#):
>
> i want one question randomly picked and show once at a time

Try something like this:

[randomquestion.xlsx](https://forum.getodk.org/uploads/short-url/39waJXudo2UhM1eCsNgGBlHpyZ8.xlsx) (8.5 KB)

Basically, generate a random number using [random()](https://docs.getodk.org/form-operators-functions/#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...
