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 >
Internet Message Format  |  1990-12-28  |  1KB

  1. From: lwall@jato.Jpl.Nasa.Gov (Larry Wall)
  2. Newsgroups: alt.sources,comp.lang.perl
  3. Subject: Re: uusched.sh: a shell script to replace broken uuscheds
  4. Message-ID: <3578@jato.Jpl.Nasa.Gov>
  5. Date: 4 May 90 07:58:33 GMT
  6.  
  7. In article <11614@netcom.UUCP> gam@netcom.uucp (Gordon Moffett) writes:
  8. : I'd like to see other ways of doing what 'shuffle' does, as long as it
  9. : allows for completely random results, like the last line of input
  10. : being the first line of output.
  11. : #!/bin/sh
  12. : # xshar:    Shell Archiver  (v1.22)
  13. : #
  14. : #    Run the following text with /bin/sh to create:
  15. : #      shuffle
  16. : #
  17. : sed 's/^X//' << 'SHAR_EOF' > shuffle &&
  18. : Xawk "BEGIN { srand($$) } { print int(rand()*1000000), \$0 }" $* |
  19. : Xsort -n |
  20. : Xsed 's/^[0-9]* //'
  21. : SHAR_EOF
  22.  
  23. You are lost in a maze of twisty little pipes, all alike.
  24.  
  25. How about:
  26.  
  27. #!/usr/bin/perl
  28. srand; @x=<>; print splice(@x,rand @x,1) while @x;
  29.  
  30. Of course, it's silly to go to all that effort just to pick one line.
  31. You do that like this:
  32.  
  33. #!/usr/bin/perl
  34. srand; @x=<>; print $x[rand @x];
  35.  
  36. Of course, if you really like to start zillions of processes, don't let
  37. me stop you...
  38.  
  39. Larry Wall
  40. lwall@jpl-devvax.jpl.nasa.gov
  41.