uusched.sh: a shell script to replace broken uuscheds

Larry Wall lwall at jato.Jpl.Nasa.Gov
Fri May 4 17:58:33 AEST 1990


In article <11614 at netcom.UUCP> gam at netcom.uucp (Gordon Moffett) writes:
: I'd like to see other ways of doing what 'shuffle' does, as long as it
: allows for completely random results, like the last line of input
: being the first line of output.
: 
: #!/bin/sh
: # xshar:	Shell Archiver  (v1.22)
: #
: #	Run the following text with /bin/sh to create:
: #	  shuffle
: #
: sed 's/^X//' << 'SHAR_EOF' > shuffle &&
: Xawk "BEGIN { srand($$) } { print int(rand()*1000000), \$0 }" $* |
: Xsort -n |
: Xsed 's/^[0-9]* //'
: SHAR_EOF

You are lost in a maze of twisty little pipes, all alike.

How about:

#!/usr/bin/perl
srand; @x=<>; print splice(@x,rand @x,1) while @x;

Of course, it's silly to go to all that effort just to pick one line.
You do that like this:

#!/usr/bin/perl
srand; @x=<>; print $x[rand @x];

Of course, if you really like to start zillions of processes, don't let
me stop you...

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Alt.sources mailing list