in reply to A series of random number and others
use warnings; use strict; my $limit = 40_000_000; my $how_many = $limit/2; my $hits = 0; open (my $handle, 'rand_sorted.txt') or die "Unable to open rand_sorte +d.txt: $!"; # Using a C style loop to avoid a large temp list (Grandfather) for (my $i = 0; $i < $limit && $hits < $how_many; $i++) { my $record = <$handle>; if (rand(2) > 1 || ($limit-$i) <= $hits ) { $hits++; # Do what you must to the record print "$i: $record\n"; } } close ($handle);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A series of random number and others
by GrandFather (Saint) on Oct 09, 2008 at 08:53 UTC |