Randomly select two members of household

Good day,

I have a questionnaire where I have to randomly select a maximum of two members of the household above the age of 14. when a household consist of 1 member above 14, you interview 1, if a household consist of 2 members above the age of 14, you interview both, and if a household consist of 3 household members above the age of 14, the macros should randomly select 2 members of the 3.

We have been using the following code to randomly select a single a member of the household.
(new Func(() =>

// create a set containing the rowcode of all adult members of the household
var adultIDs = Prsninf.Where(x => x.Age >= 15).Select(y=>y.@rowcode).ToArray();

// count the number of elements in the set
var adultCount = Prsninf.Where(x => x.Age >= 15).Count();

// create random integer between 0 and the number of adults (minus 1, since array is zero-indexed)
var randomNorm = (this.Quest.IRnd() * adultCount) - 1;
var randomInt = Math.Ceiling(randomNorm);

// store rowcode of randomly selected adult–that is, the rowcode of the adult whose array index number matches the random number
decimal selectedAdultID = adultIDs[(int) randomInt];

return (@rowcode == selectedAdultID) ;


Please assist.



see section “Random selection of 2 persons in HH” of the “Public example User questions and common patterns” questionnaire.

Best, Sergiy

1 Like

hi sergiy,
can you please give the link of above example. I am not being able to find it.
thanks and regards

You can find the section Sergiy is referring to here.

Thanks a lot. My problem is resolved