Leser: 1
![]() |
|< 1 2 3 >| | ![]() |
25 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
my $srand_init
sub rand_int
{
my $n = shift();
$srand_init = (($srand_init * 4096) + 150889) % 714025;
return int(($srand_init / 714025) * $n);
}
1
2
3
4
5
6
7
8
use strict;
use warnings;
binmode STDOUT;
for ( 1 .. $ARGV[1] ) {
print pack( "S", int rand( $ARGV[0] ) );
}
1
2
3
4
5
6
7
8
9
10
11
use strict;
use warnings;
open( FILE, "<$ARGV[0]" ) or die "$!";
while ( sysread( FILE, $_, 2 ) == 2 ) {
print unpack( "S", $_ );
print "\n";
}
close FILE;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
use strict;
use warnings;
use Digest::MD5 ();
sub digest_mix {
my ($random1) = @_;
my $ctx = Digest::MD5->new;
for my $i (0 .. 3) {
$ctx->add($random1 & 0xff);
$random1 >>= 8;
}
return $ctx->digest;
}
{
my $_rand = time;
sub srandom {
$_rand = shift if @_;
return $_rand;
}
sub random {
$_rand = unpack("L", digest_mix($_rand));
return $_rand;
}
}
srandom(10);
for (1 .. 10) {
print random(), "\n";
}
1
2
3
4
5
6
7
my %seen = ();
$ARGV[0] ? srand(time) : srandom(time);
for (1 .. 10000000) {
my $r = $ARGV[0] ? rand() : random();
die "$_" if exists $seen{$r};
$seen{$r} = 1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl
use strict;
use warnings;
use Digest ();
use Math::BigInt ();
sub digest_mix {
my ($random1) = @_;
my $ctx = Digest->new("SHA-256");
for my $i (0 .. 31) {
my $r = $random1->copy;
my $c = $r->band(0xff);
$ctx->add($c);
$random1->brsft(8);
}
return $ctx->hexdigest;
}
{
my $_rand = Math::BigInt->new("0x" . unpack("H*", pack("L", time)));
sub srandom {
$_rand = Math::BigInt->new(shift) if @_;
return $_rand;
}
sub random {
$_rand = Math::BigInt->new("0x" . digest_mix($_rand));
return $_rand->bstr;
}
}
![]() |
|< 1 2 3 >| | ![]() |
25 Einträge, 3 Seiten |