Random selection from Roster

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
prabhustat
Posts: 72
Joined: March 17th, 2012, 10:46 am

Random selection from Roster

Post 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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Random selection from Roster

Post 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));
sokiya
Posts: 15
Joined: January 15th, 2014, 5:48 am

Re: Random selection from Roster

Post 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.
prabhustat
Posts: 72
Joined: March 17th, 2012, 10:46 am

Re: Random selection from Roster

Post by prabhustat »

Thanks, works perfect.
sokiya
Posts: 15
Joined: January 15th, 2014, 5:48 am

Re: Random selection from Roster

Post by sokiya »

Hi Gregory,
Was following up on my earlier question on selecting more than one member randomly. Thanks in advance!

Best,
Stephen.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Random selection from Roster

Post 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.
sokiya
Posts: 15
Joined: January 15th, 2014, 5:48 am

Re: Random selection from Roster

Post by sokiya »

Thanks Gregory for the way out. Much appreciated!
Post Reply