line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Random::MT; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
30891
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
154
|
|
4
|
5
|
|
|
5
|
|
24
|
use Carp; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
301
|
|
5
|
5
|
|
|
5
|
|
24
|
use DynaLoader; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
199
|
|
6
|
5
|
|
|
5
|
|
3072
|
use Time::HiRes qw(gettimeofday); # standard in Perl >= 5.8 |
|
5
|
|
|
|
|
6858
|
|
|
5
|
|
|
|
|
18
|
|
7
|
5
|
|
|
5
|
|
999
|
use vars qw( @ISA $VERSION ); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
2167
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $gen = undef; |
10
|
|
|
|
|
|
|
@ISA = qw( DynaLoader ); |
11
|
|
|
|
|
|
|
$VERSION = '1.14_1'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
bootstrap Math::Random::MT $VERSION; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
6
|
|
|
6
|
1
|
573
|
my ($class, @seeds) = @_; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
|
|
53
|
my $self = Math::Random::MT::init(); |
20
|
6
|
|
|
|
|
25
|
$self->set_seed(@seeds); |
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
|
|
20
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub set_seed |
26
|
|
|
|
|
|
|
{ |
27
|
6
|
|
|
6
|
1
|
13
|
my ($self, @seeds) = @_; |
28
|
6
|
100
|
66
|
|
|
107
|
@seeds > 1 ? $self->setup_array(@seeds) : |
29
|
|
|
|
|
|
|
$self->init_seed($seeds[0] || _rand_seed()); |
30
|
6
|
|
|
|
|
28
|
return $self->get_seed; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub srand |
34
|
|
|
|
|
|
|
{ |
35
|
3
|
|
|
3
|
1
|
176
|
my (@seeds) = @_; |
36
|
3
|
|
|
|
|
26
|
$gen = Math::Random::MT->new(@seeds); |
37
|
3
|
|
|
|
|
10
|
return $gen->get_seed; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub rand |
41
|
|
|
|
|
|
|
{ |
42
|
10
|
|
|
10
|
1
|
952
|
my ($self, $N) = @_; |
43
|
|
|
|
|
|
|
|
44
|
10
|
100
|
|
|
|
38
|
unless (ref $self) { |
45
|
6
|
|
|
|
|
7
|
$N = $self; |
46
|
6
|
100
|
|
|
|
18
|
Math::Random::MT::srand() unless defined $gen; |
47
|
6
|
|
|
|
|
6
|
$self = $gen; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
10
|
|
100
|
|
|
175
|
return ($N || 1) * $self->genrand(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Generate a random seed using the built-in PRNG. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _rand_seed { |
56
|
2
|
|
|
2
|
|
4
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Get a seed at random through Perl's CORE::rand(). We do not call |
59
|
|
|
|
|
|
|
# CORE::srand() to avoid altering the random numbers that other running |
60
|
|
|
|
|
|
|
# scripts might be using. When using _rand_seed(), the seeds obtained are |
61
|
|
|
|
|
|
|
# all different, even when doing many rapid calls to the function. |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
82
|
return int(CORE::rand(2**32)); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub import |
67
|
|
|
|
|
|
|
{ |
68
|
5
|
|
|
5
|
|
29
|
no strict 'refs'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
476
|
|
69
|
5
|
|
|
5
|
|
37
|
my $pkg = caller; |
70
|
5
|
|
|
|
|
13
|
foreach my $sym (@_) { |
71
|
11
|
100
|
100
|
|
|
3086
|
if ($sym eq "srand" || $sym eq "rand") { |
72
|
6
|
|
|
|
|
10
|
*{"${pkg}::$sym"} = \&$sym; |
|
6
|
|
|
|
|
4905
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |