:
use strict;
use warnings;
my ($pick, $file) = @ARGV;
open(my $fh, '<', $file)
or die "Can't read file '$file' [$!]\n";
my ($lines, $buffer);
while (sysread $fh, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
}
$pick = $lines if $pick > $lines;
my %picked;
for (1 .. $pick) {
my $n = int(rand($lines)) + 1;
redo if $picked{$n}++
}
seek($fh, 0, 0);
while (<$fh>) {
print if $picked{$.};
}
close $fh;