Thread Zufällige Ausgabe (12 answers)
Opened by havi at 2005-09-12 12:05

renee
 2005-09-12 12:33
#57831 #57831
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
700 selbst erzeugte Nummern
Code: (dl )
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));


700 Nummern aus der Datei:
Code: (dl )
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));
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Zufällige Ausgabe