# Selecting random multiple choice alternatives from a list

Hello,
Let's say I have a list of names of hamlets in a csv file:

Hamlet A
Hamlet B
Hamlet C
Hamlet D
Hamlet E
Hamlet F
Hamlet G
Hamlet H

I'm trying to design a set of questions where two hamlets from the list are randomly picked and the respondent has to choose between the two. For instance:

"Given hamlet X(randomly selected) and Hamlet Y (randomly selected), which do you prefer?"

The question would be repeated several of times with different, randomly selected combinations of hamlets.

Any ideas on how could I do this in ODK Collect? Thanks in advance.

I can't think of any straightforward way to do this in xlsform, but here is
one method.

random() returns a number between 0 and 1, so you can scale this to an
integer between 1 and the total number of hamlets. If the hamlet names
were a choice list and the values stored were integers, then you could get
the label in any language using jr:choice and the random integer.

This would cover hamlet X in your example but not a unique value for Y.
Let's solve another problem first.

Random will calculate at every swipe of every screen, so the random numbers
change. You probably need stable x/y pairs or else you won't know what
you're analyzing in the results.

To solve that problem, randomly generate two numbers, then use the phone
operator to transfer the randomly generated value into another variable. I
would create an integer screen as per the below pseudo code

calculate random X
calculate random Y

begin group; appearance = field_list
Type = note; label="Transfer these numbers into the text box below. If they
are the same, swipe backwards, then swipe forwards". [relevant =
(\${random_x_transcribed} != '') and (\${random_y_transcribed} != '') ]
integer: name = random_x_transcribed
integer: name = random_y_transcribed
end group
calculate jr:choice that turns random_x_transcibed into "Hamlet X"
calculate jr:choice that turns random_y_transcibed into "Hamlet Y"

Luke

··· On Friday, February 27, 2015 at 6:52:22 AM UTC+7, Werner Hertzog wrote: > > Hello, > Let's say I have a list of names of hamlets in a csv file: > > Hamlet A > Hamlet B > Hamlet C > Hamlet D > Hamlet E > Hamlet F > Hamlet G > Hamlet H > > I'm trying to design a set of questions where two hamlets from the list > are randomly picked and the respondent has to choose between the two. For > instance: > > "Given hamlet X(randomly selected) and Hamlet Y (randomly selected), which > do you prefer?" > > The question would be repeated several of times with different, randomly > selected combinations of hamlets. > > Any ideas on how could I do this in ODK Collect? Thanks in advance.

Note that the function once() wrapping a calculation ensures that if the
field already has a value, it will not be changed.

So you can ensure that a random value, once generated, is never re-computed
by writing:

once(random())

in the calculate column.

··· On Mon, Mar 2, 2015 at 9:26 AM, Luke MacDonald wrote:

I can't think of any straightforward way to do this in xlsform, but here
is one method.

random() returns a number between 0 and 1, so you can scale this to an
integer between 1 and the total number of hamlets. If the hamlet names
were a choice list and the values stored were integers, then you could get
the label in any language using jr:choice and the random integer.

This would cover hamlet X in your example but not a unique value for Y.
Let's solve another problem first.

Random will calculate at every swipe of every screen, so the random
numbers change. You probably need stable x/y pairs or else you won't know
what you're analyzing in the results.

To solve that problem, randomly generate two numbers, then use the phone
operator to transfer the randomly generated value into another variable. I
would create an integer screen as per the below pseudo code

calculate random X
calculate random Y

begin group; appearance = field_list
Type = note; label="Transfer these numbers into the text box below. If
they are the same, swipe backwards, then swipe forwards". [relevant =
(\${random_x_transcribed} != '') and (\${random_y_transcribed} != '') ]
integer: name = random_x_transcribed
integer: name = random_y_transcribed
end group
calculate jr:choice that turns random_x_transcibed into "Hamlet X"
calculate jr:choice that turns random_y_transcibed into "Hamlet Y"

Luke

On Friday, February 27, 2015 at 6:52:22 AM UTC+7, Werner Hertzog wrote:

Hello,
Let's say I have a list of names of hamlets in a csv file:

Hamlet A
Hamlet B
Hamlet C
Hamlet D
Hamlet E
Hamlet F
Hamlet G
Hamlet H

I'm trying to design a set of questions where two hamlets from the list
are randomly picked and the respondent has to choose between the two. For
instance:

"Given hamlet X(randomly selected) and Hamlet Y (randomly selected),
which do you prefer?"

The question would be repeated several of times with different, randomly
selected combinations of hamlets.

Any ideas on how could I do this in ODK Collect? Thanks in advance.

## --

You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Great tip Mitch.

··· --------- Luke H MacDonald, PhD m: +1 (609) 751-4556 Skype: Luke.h.macdonald Email: luke.h.macdonald@gmail.com Twitter: @lukehmacdonald

Sent from my iPhone

On Mar 3, 2015, at 5:09 AM, Mitch Sundt mitchellsundt@gmail.com wrote:

Note that the function once() wrapping a calculation ensures that if the field already has a value, it will not be changed.

So you can ensure that a random value, once generated, is never re-computed by writing:

once(random())

in the calculate column.

On Mon, Mar 2, 2015 at 9:26 AM, Luke MacDonald luke.h.macdonald@gmail.com wrote:
I can't think of any straightforward way to do this in xlsform, but here is one method.

random() returns a number between 0 and 1, so you can scale this to an integer between 1 and the total number of hamlets. If the hamlet names were a choice list and the values stored were integers, then you could get the label in any language using jr:choice and the random integer.

This would cover hamlet X in your example but not a unique value for Y. Let's solve another problem first.

Random will calculate at every swipe of every screen, so the random numbers change. You probably need stable x/y pairs or else you won't know what you're analyzing in the results.

To solve that problem, randomly generate two numbers, then use the phone operator to transfer the randomly generated value into another variable. I would create an integer screen as per the below pseudo code

calculate random X
calculate random Y

begin group; appearance = field_list
Type = note; label="Transfer these numbers into the text box below. If they are the same, swipe backwards, then swipe forwards". [relevant = (\${random_x_transcribed} != '') and (\${random_y_transcribed} != '') ]
integer: name = random_x_transcribed
integer: name = random_y_transcribed
end group
calculate jr:choice that turns random_x_transcibed into "Hamlet X"
calculate jr:choice that turns random_y_transcibed into "Hamlet Y"

Luke

On Friday, February 27, 2015 at 6:52:22 AM UTC+7, Werner Hertzog wrote:
Hello,
Let's say I have a list of names of hamlets in a csv file:

Hamlet A
Hamlet B
Hamlet C
Hamlet D
Hamlet E
Hamlet F
Hamlet G
Hamlet H

I'm trying to design a set of questions where two hamlets from the list are randomly picked and the respondent has to choose between the two. For instance:

"Given hamlet X(randomly selected) and Hamlet Y (randomly selected), which do you prefer?"

The question would be repeated several of times with different, randomly selected combinations of hamlets.

Any ideas on how could I do this in ODK Collect? Thanks in advance.

## --

You received this message because you are subscribed to the Google Groups "ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit+unsubscribe@googlegroups.com.