Leser: 1
|< 1 2 >| | 13 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my $max = 700;
my %seen = ();
my $run = 1;
while($run) {
my $lncount = 0;
while(<IN>) {
my $r = int(rand(2));
if($r == 0 and not exists $seen{$lncount}) {
print OUT $_;
$seen{$lncount} = 1;
--$max;
if($max == 0) {
$run = 0;
last;
}
}
++$lncount;
}
seek(IN, 0, 0) if $run;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
use strict;
use warnings;
my %hash = ();
my $max = 60_000;
my $count = 700;
while(keys(%hash) < $count-1){
$hash{int rand($max)} = 1;
}
print scalar(keys(%hash));
print $_,"\n" for(keys(%hash));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;
my %hash = ();
my $file = '/path/to/file.txt';
my $count = 700;
tie my @array,'Tie::File',$file or die $!;
while(keys(%hash) < $count-1){
$hash{$array[int rand(scalar(@array)-1)]} = 1;
}
untie @array;
print scalar(keys(%hash));
print $_,"\n" for(keys(%hash));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my $max = 700;
my %seen = ();
my $run = 1;
while($run) {
my $lncount = 0;
while(<IN>) {
my $r = int(rand(2));
if($r == 0 and not exists $seen{$lncount}) {
print OUT $_;
$seen{$lncount} = 1;
--$max;
if($max == 0) {
$run = 0;
last;
}
}
++$lncount;
}
seek(IN, 0, 0) if $run;
}
|< 1 2 >| | 13 Einträge, 2 Seiten |