Page 1 of 1

How to select 5% people in a roster (randomly)

Posted: August 26th, 2013, 7:23 am
by manojorb
Dear Sir,

How to automatically select 5% people in a roster (randomly) and people name should be shown in a dialog box.

Thanks
Manoj

Re: How to select 5% people in a roster (randomly)

Posted: September 4th, 2013, 11:51 am
by Gregory Martin
I would suggest maintaining an array (or using a repeating item in the working storage dictionary) to maintain a flag of whether or not you have sampled a given occurrence.

Then loop through the people in your roster, and write something like this:
numeric number_to_select = {fill this in somehow, making it a whole number};
numeric number_selected = 0;
numeric occurrence_number;

while number_selected < number_to_select do

    
do occurrence_number = 1 while number_selected < number_to_select and occurrence_number <= totocc(PERSON)

        
if random(1,100) <= 5 then
            FLAG(occurrence_number) =
1;
            
inc(number_selected);
        
endif;

    
enddo;

enddo;
After this loop runs, you have your 5% sample (where FLAG = 1), and you can add these people to a roster of selected persons.