Random selection from a "double roster"

Dear all,

The difference between my case and the “Public example Random Demo” is that my random selection is based on a “double roster”.
My first roster is based on a list of parcels. For each parcel, there is a question “How many animal houses are there on this parcel (b104)?”. The second roster is based on this numeric question. My target is to randomly select an animal house among the houses that are for raising chicken.

We have came up with a potential solution that is based on only the first roster: 1) Random selection a parcel among the parcels that have chicken houses; 2) Randomly select a number between 1 and the number of chicken houses of this selected parcel. However, there is a problem with this solution. Because the number of chicken houses on each parcel can be different, the probability of each parcel being selected should be different (based on the number of chicken houses). I should assign a “weight” (i.e. number of chicken houses") to the random selection in the first step.
I couldn’t find any topic in the forum about this issue. Please help!

My syntax are in below:

Variable: num_parcel (number of eligible parcel with chicken houses)
Expression: Parcel_roster.Count($Parcel_with_chicken_house)

Var: random_index_parcel (random index of eligible parcel with house)
Expression: (long)Math.Floor(Quest.IRnd()*num_parcel.Value)

Var: random_rowcode_parcel (Random eligible respondent rowcode (parcel with house))
Expression:Parcel_roster.Where($Parcel_with_house).Select(z=>z.@rowcode).ToArray()[random_index_parcel.Value]

Var: selected_parcel (Randomly selected parcel)
Expression: parcel_list.Where(x=>x.Item1==random_rowcode_parcel).First().Item2

Var: sp_index (selected parcel index)
Expression: parcel_list.Where(x=>x.Item2==selected_parcel).First().Item1

Var: sp_b104 (selected parcel’s number of chicken houses)
Expression: parcel_list.Where(x=>x.Item2==selected_parcel).First().Item1

Var: random_house_index (random house index of selected parcel)
Expression: (long)Math.Floor(Quest.IRnd()*sp_b104.Value)

Thanks much,
Percy

Dear Percy,

It is a bit hard to get, what is your final goal.

  1. Do you want to select only one random chicken house and ask some questions about it?
  2. Do you want to select only one random chicken house for each parcel?
  3. Do you want to select some number of chicken houses for each parcel, based on a total number of the chicken houses?

Regards,
Slava.

Hi Slava,

Thanks much for your reply and pointing out the unclear part of my question.
My final goal is to select only one random chicken house and ask questions.

Best,
Percy

I added public a example for this case: https://designer.mysurvey.solutions/questionnaire/details/4eceee04e02846e185d699dbddeef562

Please take a look and let me know if this is what your tried to implement or not.

Regards,
Slava

1 Like

Hi Slava,

It’s working!! Thanks much. I will incorporate this into my questionnaire and let you know if I find new questions.

All the best,
Percy