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