Page 1 of 1

Random selection from Roster

Posted: May 24th, 2018, 1:58 pm
by prabhustat
Hi,
I need to select randomly one member from the roster and I want to display the selected member name. If any one has example, please share it.

Thanks
PP

Re: Random selection from Roster

Posted: May 24th, 2018, 5:13 pm
by Gregory Martin
How about using the random function?
seed(systime());

numeric occurrence_to_select = random(1, count(NAME));

errmsg("I selected %s", NAME(occurrence_to_select));

Re: Random selection from Roster

Posted: May 25th, 2018, 11:40 am
by sokiya
Thanks Greg for the work around.
Was thinking aloud if one needed two or more randomly selected persons. The trick here would be to avoid duplicates in the generated random numbers.

Re: Random selection from Roster

Posted: May 26th, 2018, 5:24 am
by prabhustat
Thanks, works perfect.

Re: Random selection from Roster

Posted: June 5th, 2018, 6:54 am
by sokiya
Hi Gregory,
Was following up on my earlier question on selecting more than one member randomly. Thanks in advance!

Best,
Stephen.

Re: Random selection from Roster

Posted: June 5th, 2018, 7:31 am
by Gregory Martin
If you only cared about two, you could do this:
numeric occurrence1_to_select = random(1, count(NAME));
numeric occurrence2_to_select = occurrence1_to_select;

while occurrence1_to_select = occurrence2_to_select do
    occurrence2_to_select = random(1, count(NAME))
enddo;
You could generalize this for more than two by using an array to store the selected members.

Re: Random selection from Roster

Posted: June 5th, 2018, 7:35 am
by sokiya
Thanks Gregory for the way out. Much appreciated!