line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Gimei::Random; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pseudo random number generator(PRNG) |
4
|
|
|
|
|
|
|
# Park & Miller comp.lang.c FAQ list Question 13.15 |
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
6354
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
172
|
|
7
|
6
|
|
|
6
|
|
55
|
use v5.22; |
|
6
|
|
|
|
|
18
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
|
|
34
|
use Class::Tiny qw ( |
10
|
|
|
|
|
|
|
seed |
11
|
6
|
|
|
6
|
|
422
|
); |
|
6
|
|
|
|
|
2468
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub BUILDARGS { |
14
|
|
|
|
|
|
|
#my $class = shift; |
15
|
|
|
|
|
|
|
#my %args = @_; |
16
|
8
|
|
|
8
|
0
|
1034
|
my ( $class, %args ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
33
|
|
|
64
|
$args{'seed'} //= time(); |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
19
|
return \%args; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub set_seed { |
24
|
9
|
|
|
9
|
0
|
106
|
my ( $self, $seed ) = @_; |
25
|
9
|
|
|
|
|
161
|
$self->seed( $seed ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub next_int { |
29
|
57
|
|
|
57
|
0
|
139
|
my ( $self, $size ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
57
|
|
|
|
|
960
|
my $rnum = (48_271 * $self->seed) % (2 << 31 -1); |
32
|
57
|
|
|
|
|
950
|
$self->seed( $rnum ); |
33
|
|
|
|
|
|
|
|
34
|
57
|
|
|
|
|
222
|
return $rnum % $size; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub sample { |
38
|
52
|
|
|
52
|
0
|
91
|
my ( $self, $aref ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
52
|
|
|
|
|
91
|
my $index = $self->next_int($#$aref + 1); |
41
|
|
|
|
|
|
|
|
42
|
52
|
|
|
|
|
195
|
return $aref->[$index]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
1; |