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