#!/usr/bin/perl

# randomize source file
# lines are output in random order

# reads from from stdin or arg0, writes to stdout or arg1
open (STDIN, $ARGV[0]) if (($ARGV[0] ne "") && ($ARGV[0] ne "-"));
open (STDOUT, ">$ARGV[1]") if ($ARGV[1] ne "");

@list = <STDIN>;

while (@list) {
  $rand = rand (@list);
  print $list[$rand];              # for indexing rand is truncated
  splice @list, $rand, 1;          # delete array element
}

