in reply to Re (tilly) 2 (unrandomness): Extract random records from text file
in thread Extract random records from text file
my $num = shift; my @init = (0..$num-1); my @questions; while (<>) { $questions[splice @init, rand(@init), 1] = $_, next if $. <= $num; my $i = rand($.); $questions[$i] = $_ if $i < $num; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 4 (unrandomness): Extract random records from text file
by tilly (Archbishop) on Oct 03, 2001 at 21:30 UTC |