home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1264
< prev
next >
Wrap
Internet Message Format
|
1990-12-28
|
1KB
From: lwall@jato.Jpl.Nasa.Gov (Larry Wall)
Newsgroups: alt.sources,comp.lang.perl
Subject: Re: uusched.sh: a shell script to replace broken uuscheds
Message-ID: <3578@jato.Jpl.Nasa.Gov>
Date: 4 May 90 07:58:33 GMT
In article <11614@netcom.UUCP> gam@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@jpl-devvax.jpl.nasa.gov