# Select a random number/kishGrid

Hello everyone,

I am new to ODK. Could you please help me to know how to select a random
number out of a total number of the HH members?

In other words, if the total number of the HH members is 7, we want to
select a random number/member out of the 7 members (from 1 to 7), how can
we implement this in XLSForm?

Looking forward to hearing from you.

All the Best,

Ali Helmi

Hi Ali,

The general approach would be to have a calculated field such as:

once(int(7*random())+1)

This would generate a random number between 1 and 7, inclusive.

Yaw

ยทยทยท On Tue, Feb 28, 2017 at 9:35 AM, Ali Helmi wrote: > Hello everyone, > > I am new to ODK. Could you please help me to know how to select a random > number out of a total number of the HH members? > > In other words, if the total number of the HH members is 7, we want to > select a random number/member out of the 7 members (from 1 to 7), how can we > implement this in XLSForm? > > Looking forward to hearing from you. > > All the Best, > > Ali Helmi > > -- > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en > > --- > 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. > For more options, visit https://groups.google.com/d/optout.

Hi Yaw,

Thank you so much for your help on this.

I have replaced the number 7 in the code

once(int(7*random())+1)

to be the variable name of the total number of members in the HH

once(int(\${hh_num}random())+1)
My question now is, what happen if we delete
(+1) at the end of the code?
and what does (
+1*) do?

All My Best Regards,

Ali

Ali,

See https://opendatakit.github.io/xforms-spec for the definition of
random(). It says "Returns a random number between 0.0 (inclusive) and
1.0 (exclusive)."

So, the +1 moves the range of possible numbers up 1 so you don't get
zero. Try removing it and try it out!

Thanks,

Yaw