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
Random selection from Roster
-
- Posts: 1796
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Random selection from Roster
How about using the random function?
seed(systime());
numeric occurrence_to_select = random(1, count(NAME));
errmsg("I selected %s", NAME(occurrence_to_select));
numeric occurrence_to_select = random(1, count(NAME));
errmsg("I selected %s", NAME(occurrence_to_select));
Re: Random selection from Roster
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.
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.
-
- Posts: 72
- Joined: March 17th, 2012, 10:46 am
Re: Random selection from Roster
Thanks, works perfect.
Re: Random selection from Roster
Hi Gregory,
Was following up on my earlier question on selecting more than one member randomly. Thanks in advance!
Best,
Stephen.
Was following up on my earlier question on selecting more than one member randomly. Thanks in advance!
Best,
Stephen.
-
- Posts: 1796
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Random selection from Roster
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.numeric occurrence2_to_select = occurrence1_to_select;
while occurrence1_to_select = occurrence2_to_select do
occurrence2_to_select = random(1, count(NAME))
enddo;
Re: Random selection from Roster
Thanks Gregory for the way out. Much appreciated!