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) ;
})).Invoke()
Please assist.
regards
Rabelani