#!/usr/bin/perl
# The Missing Textutils, Ondrej Bojar, obo@cuni.cz
# http://www.cuni.cz/~obo/textutils
#
# 'shuffle' is the missing complement to 'sort'. Correctly shuffles the input
# lines.
#
# $Id: shuffle,v 1.2 2005/10/10 07:33:50 bojar Exp $
#

use Getopt::Long;

$limit = 0;
GetOptions("limit=i" => \$limit);

while (<>) {
  push @lines, $_;
}

while (@lines) {
  $nr++;
  $rnd = int(rand($#lines+1));
  print $lines[$rnd];
  splice(@lines, $rnd, 1);
  last if $limit && $nr >= $limit;
}
