line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Random::MTwist; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
80272
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
137
|
|
4
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
113
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
25
|
use Exporter; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
141
|
|
7
|
4
|
|
|
4
|
|
1482
|
use Time::HiRes; # for timeseed() |
|
4
|
|
|
|
|
5114
|
|
|
4
|
|
|
|
|
18
|
|
8
|
4
|
|
|
4
|
|
448
|
use XSLoader; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
138
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
24
|
use constant MT_TIMESEED => \0; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
358
|
|
11
|
4
|
|
|
4
|
|
30
|
use constant MT_FASTSEED => \0; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
212
|
|
12
|
4
|
|
|
4
|
|
25
|
use constant MT_GOODSEED => \0; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
229
|
|
13
|
4
|
|
|
4
|
|
26
|
use constant MT_BESTSEED => \0; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1346
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @ISA = 'Exporter'; |
18
|
|
|
|
|
|
|
our @EXPORT = qw(MT_TIMESEED MT_FASTSEED MT_GOODSEED MT_BESTSEED); |
19
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT; |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
21
|
|
|
|
|
|
|
'rand' => [ |
22
|
|
|
|
|
|
|
qw(srand rand rand32 rand64 irand irand32 irand64 irand128 randstr) |
23
|
|
|
|
|
|
|
], |
24
|
|
|
|
|
|
|
'seed' => [qw(seed32 seedfull timeseed fastseed goodseed bestseed)], |
25
|
|
|
|
|
|
|
'state' => [qw(savestate loadstate getstate setstate)], |
26
|
|
|
|
|
|
|
'dist' => [ |
27
|
|
|
|
|
|
|
qw( |
28
|
|
|
|
|
|
|
rd_double |
29
|
|
|
|
|
|
|
rd_iuniform rd_iuniform32 rd_iuniform64 |
30
|
|
|
|
|
|
|
rd_uniform rd_luniform |
31
|
|
|
|
|
|
|
rd_erlang rd_lerlang |
32
|
|
|
|
|
|
|
rd_exponential rd_lexponential |
33
|
|
|
|
|
|
|
rd_lognormal rd_llognormal |
34
|
|
|
|
|
|
|
rd_normal rd_lnormal |
35
|
|
|
|
|
|
|
rd_triangular rd_ltriangular |
36
|
|
|
|
|
|
|
rd_weibull rd_lweibull |
37
|
|
|
|
|
|
|
) |
38
|
|
|
|
|
|
|
], |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$EXPORT_TAGS{all} = [ map @$_, values %EXPORT_TAGS ]; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
XSLoader::load('Math::Random::MTwist', $VERSION); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# We want the function-oriented interface to provide the same function names as |
46
|
|
|
|
|
|
|
# the OO interface. But since it doesn't have the state argument (aka $self), |
47
|
|
|
|
|
|
|
# MTwist.xs provides counterparts with a leading underscore that we map to here. |
48
|
|
|
|
|
|
|
sub import { |
49
|
4
|
|
|
4
|
|
37
|
my $this = shift; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
17
|
my @unhandled_args; |
52
|
|
|
|
|
|
|
|
53
|
4
|
100
|
|
|
|
18
|
if (@_) { |
54
|
1
|
|
|
|
|
4
|
my $caller = caller; |
55
|
1
|
|
|
|
|
2
|
my $need4seed = 0; |
56
|
1
|
|
|
|
|
3
|
my %exportable = map +($_ => 1), @{$EXPORT_TAGS{all}}; |
|
1
|
|
|
|
|
25
|
|
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
8
|
while (defined(my $arg = shift)) { |
59
|
41
|
100
|
66
|
|
|
172
|
if ($arg =~ /^:(.+)/ && exists $EXPORT_TAGS{$1}) { |
|
|
50
|
|
|
|
|
|
60
|
4
|
|
|
|
|
9
|
push @_, @{$EXPORT_TAGS{$1}}; |
|
4
|
|
|
|
|
27
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ($exportable{$arg}) { |
63
|
4
|
|
|
4
|
|
52
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1257
|
|
64
|
37
|
|
|
|
|
61
|
$need4seed++; |
65
|
37
|
|
|
|
|
98
|
*{"$caller\::$arg"} = \&{"$this\::_$arg"}; |
|
37
|
|
|
|
|
212
|
|
|
37
|
|
|
|
|
122
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
0
|
|
|
|
|
0
|
push @unhandled_args, $arg; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
50
|
|
|
|
41
|
_fastseed() if $need4seed; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
4
|
|
|
|
|
434
|
__PACKAGE__->export_to_level(1, $this, @unhandled_args); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub new { |
79
|
1
|
|
|
1
|
1
|
100
|
my $class = shift; |
80
|
1
|
|
|
|
|
2
|
my $seed = shift; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
18
|
my $self = new_state($class); |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
5
|
if (! defined $seed) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
85
|
1
|
|
|
|
|
26
|
$self->fastseed(); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif (! ref $seed) { |
88
|
0
|
|
|
|
|
0
|
$self->seed32($seed); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif (ref $seed eq 'ARRAY') { |
91
|
0
|
|
|
|
|
0
|
$self->seedfull($seed); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ($seed == MT_TIMESEED) { |
94
|
0
|
|
|
|
|
0
|
$self->timeseed(); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif ($seed == MT_FASTSEED) { |
97
|
0
|
|
|
|
|
0
|
$self->fastseed(); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif ($seed == MT_GOODSEED) { |
100
|
0
|
|
|
|
|
0
|
$self->goodseed(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ($seed == MT_BESTSEED) { |
103
|
0
|
|
|
|
|
0
|
$self->bestseed(); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { # WTF? |
106
|
0
|
|
|
|
|
0
|
$self->fastseed(); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
5
|
$self; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |