Xref: utzoo alt.sources:1834 comp.lang.perl:1250 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!lwall 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 References: <11614@netcom.UUCP> Reply-To: lwall@jato.Jpl.Nasa.Gov (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 35 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