Results 1 to 6 of 6
Hello,
This may sound like a silly or naive request, but I have ten names and I need to create 60 random lists out of these ten names where no ...
- 03-11-2007 #1Linux User
- Join Date
- Aug 2005
- Posts
- 408
random lists
Hello,
This may sound like a silly or naive request, but I have ten names and I need to create 60 random lists out of these ten names where no name can repeat in any one list. This may sound like a homework problem, but if you're wondering what the application is, I'm actually coaching a baseball team, and it's easier to just put all 10 kids' names into a program and have it spit out randomly sorted lists of their names for all the different switching of positions for the rest of the season. This way it doesn't seem like any one kid gets to be pitcher any more than any other kid, for instance.
I thought there would be easy ways to do this, but I'm having trouble figuring it out.
I started with this:
But that gives me a list with some names repeated. Is there an easy way to do this or something I'm missing?Code:count=0 while [ "$count" -le 10 ] do Player="Dakota Sean Jose Diego John Nicholas James Gabe Austin Trey" player=($Player) num_player=${#player[*]} echo "${player[$((RANDOM%num_player))]} " let count=count+1 done exit 0
- 03-11-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
In this script I'm supposing that you have the names of the players in the file "myfile" (make sure you have a backup).
The script echoes the chosen name on the screen.
RegardsCode:#!/bin/sh # Read number of lines nlines=$(wc -l myfile|cut -d " " -f1) if [ $nlines -lt 1 ]; then echo "No more lines in myfile" exit 1 fi # A random number between 1 and nlines number=$(($RANDOM % $nlines)) let "number=number+1" # Now echo the chosen name sed -n ''$number' p' myfile # Update myfile for the next time and make a backup sed -i.backup ''$number','$number' d' file exit 0
- 03-11-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Good coaching. I think the phrase without replacement is a key concept. Here's one way:
Which produces this:Code:#!/bin/sh # @(#) s1 Demonstrate random choice without replacement. # "without replacement", i.e., one deliberately avoids choosing # any member of the population more than once. # # http://en.wikipedia.org/wiki/Simple_random_sample_without_replacement debug="echo" debug=":" List="Dakota Sean Jose Diego John Nicholas James Gabe Austin Trey" player=($List) num_player=${#player[*]} $debug " num_player = $num_player" count=0 while [ "$count" -lt $num_player ] do slot=$((RANDOM%num_player)) $debug " slot is $slot" while [ "${player[$slot]}" = "" ] do slot=$((RANDOM%num_player)) done echo "${player[$slot]}" player[$slot]="" count=$((count+1)) $debug " count is $count" done exit 0
and this:Code:% ./s1 Trey Diego John Nicholas James Sean Gabe Jose Austin Dakota
and so on.Code:% ./s1 James Nicholas John Jose Gabe Sean Dakota Diego Austin Trey
Good luck with the team! ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-11-2007 #4Linux User
- Join Date
- Aug 2005
- Posts
- 408
Wow. Thanks a lot for your help. I really appreciate it.
I've actually discovered that setting the positions like this for a kid's team works really well because it makes all of the kids start to understand the function of each position as they all have to play each position, and when they can understand that, then they can actually function as a team.
Anyway, I have one more (minor) question to ask. I'm not sure if this is even possible, so please bear with me and feel free to tell me if the answer is too involved to work out here.
It's great to have random lists, and I can use what you put together so far throughout the season, but one thing that would help is to have the program spit out about 50 of these random lists, and to have one of the positions on the list (say the last position, for instance) not have a name repeated until after nine cycles through the program. The reason for that is that the last place on the list is the "bench" position (for a 10-kid team), so in order to have no one sit out more than anyone else, it would be nice to have a kid not sit on the bench until the other nine kids have.
Does that make sense? Is it possible or even easy to do? I have absolutely no idea how to do it, but if it's too difficult, I'll just work with what I have.
Thanks again!
- 03-11-2007 #5Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
I probably don't understand your question, but here are my thoughts.
Are you asking for a "shift", such as rotating the list of names like this:
That's a fairly easy thing to set up, yes?Code:p c 1 2 3 s l c r b Dakota Sean Jose Diego John Nicholas James Gabe Austin Trey p c 1 2 3 s l c r b Sean Jose Diego John Nicholas James Gabe Austin Trey Dakota
You could even get the players to help you with that so that they could also see what some of your responsibilities are like.
I'm not a coach, but I'd say that a predetermined order would be useful. The person on the bench knows that he/she will cycle into right field so that player can be observed. The right fielder will cycle into center, and so on. So instead of watching all players, only the tactical situation needs to be in one's thoughts, and the observer can see what might be good to keep, and bad to not repeat for the next position into which he will be shifted.
However, I am way out of my field (pun intended) here, so my non-technical advice is worth what you paid for it
... cheers, drl
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-11-2007 #6Linux User
- Join Date
- Aug 2005
- Posts
- 408
Hahahah.
I think what I was asking about was whether or not it would be possible to just "shift" the very last entry (bench), which would keep all the others pretty random, but make it so that no one sits out more than anyone else.
That's alright, though. I'll work with the answers you guys have given.
Thanks again.


Reply With Quote