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