line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Random::ISAAC; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
34536
|
$Math::Random::ISAAC::VERSION = '1.004'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Perl interface to the ISAAC PRNG algorithm |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
20
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
8
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
59
|
|
9
|
2
|
|
|
2
|
|
11
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
709
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $DRIVER = 'PP'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Try to load the XS version first |
14
|
|
|
|
|
|
|
eval { |
15
|
|
|
|
|
|
|
require Math::Random::ISAAC::XS; |
16
|
|
|
|
|
|
|
$DRIVER = 'XS'; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Fall back on the Perl version |
20
|
|
|
|
|
|
|
if ($@) { |
21
|
|
|
|
|
|
|
require Math::Random::ISAAC::PP; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Wrappers around the actual methods |
26
|
|
|
|
|
|
|
sub new { |
27
|
2
|
|
|
2
|
1
|
16
|
my ($class, @seed) = @_; |
28
|
|
|
|
|
|
|
|
29
|
2
|
100
|
|
|
|
160
|
Carp::croak('You must call this as a class method') if ref($class); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
2
|
my $self = { |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
5
|
if ($DRIVER eq 'XS') { |
35
|
1
|
|
|
|
|
18
|
$self->{backend} = Math::Random::ISAAC::XS->new(@seed); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
0
|
|
|
|
|
0
|
$self->{backend} = Math::Random::ISAAC::PP->new(@seed); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
bless($self, $class); |
42
|
1
|
|
|
|
|
4
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# This package should have an interface similar to the builtin Perl |
47
|
|
|
|
|
|
|
# random number routines; these are methods, not functions, so they |
48
|
|
|
|
|
|
|
# are not problematic |
49
|
|
|
|
|
|
|
## no critic (ProhibitBuiltinHomonyms) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub rand { |
52
|
1
|
|
|
1
|
1
|
408
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
113
|
Carp::croak('You must call this method as an object') unless ref($self); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
return $self->{backend}->rand(); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub irand { |
61
|
1
|
|
|
1
|
1
|
423
|
my ($self) = @_; |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
118
|
Carp::croak('You must call this method as an object') unless ref($self); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $self->{backend}->irand(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |