line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# returns Pseudo Random Distribution random functions |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Game::PseudoRand; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
52989
|
use 5.10.0; |
|
2
|
|
|
|
|
11
|
|
8
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
41
|
|
9
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
10
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
873
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(prd_step prd_table); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub prd_step { |
19
|
12
|
|
|
12
|
1
|
3608
|
my %param = @_; |
20
|
|
|
|
|
|
|
croak "prd_step requires start and step values" |
21
|
|
|
|
|
|
|
unless exists $param{start} |
22
|
12
|
100
|
100
|
|
|
90
|
and exists $param{step}; |
23
|
|
|
|
|
|
|
croak "prd_step rand must be a code ref" |
24
|
7
|
100
|
100
|
|
|
28
|
if defined $param{rand} and ref $param{rand} ne 'CODE'; |
25
|
6
|
|
|
|
|
12
|
my $odds = $param{start}; |
26
|
6
|
|
66
|
|
|
16
|
my $reset = $param{reset} // $odds; |
27
|
6
|
|
100
|
10
|
|
25
|
my $rand = $param{rand} // sub { CORE::rand }; |
|
10
|
|
|
|
|
63
|
|
28
|
6
|
|
|
|
|
9
|
my $step = $param{step}; |
29
|
|
|
|
|
|
|
( sub { |
30
|
12
|
100
|
|
12
|
|
55
|
if ( &$rand <= $odds ) { $odds = $reset; 1 } |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
12
|
|
31
|
8
|
|
|
|
|
15
|
else { $odds += $step; 0 } |
|
8
|
|
|
|
|
51
|
|
32
|
|
|
|
|
|
|
}, |
33
|
1
|
|
|
1
|
|
3
|
sub { $odds = $param{start} } |
34
|
6
|
|
|
|
|
29
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub prd_table { |
38
|
13
|
|
|
13
|
1
|
3248
|
my %param = @_; |
39
|
|
|
|
|
|
|
croak "prd_table requires start and table values" |
40
|
|
|
|
|
|
|
unless exists $param{start} |
41
|
13
|
100
|
66
|
|
|
58
|
and exists $param{table}; |
42
|
|
|
|
|
|
|
croak "prd_table table must be a not-empty array ref" |
43
|
12
|
100
|
100
|
|
|
42
|
if ref $param{table} ne 'ARRAY' or !@{$param{table}}; |
|
11
|
|
|
|
|
32
|
|
44
|
|
|
|
|
|
|
croak "prd_table rand must be a code ref" |
45
|
10
|
100
|
100
|
|
|
34
|
if defined $param{rand} and ref $param{rand} ne 'CODE'; |
46
|
9
|
|
100
|
|
|
25
|
my $index = $param{index} // 0; |
47
|
9
|
|
|
|
|
10
|
my $table = [ @{$param{table}} ]; |
|
9
|
|
|
|
|
15
|
|
48
|
9
|
100
|
100
|
|
|
41
|
croak "index outside of table bounds" if $index < 0 or $index >= @$table; |
49
|
7
|
|
|
|
|
9
|
my $odds = $param{start}; |
50
|
7
|
|
66
|
|
|
16
|
my $reset = $param{reset} // $odds; |
51
|
7
|
|
100
|
18
|
|
24
|
my $rand = $param{rand} // sub { CORE::rand }; |
|
18
|
|
|
|
|
51
|
|
52
|
|
|
|
|
|
|
( sub { |
53
|
20
|
100
|
|
20
|
|
74
|
if ( &$rand <= $odds ) { $odds = $reset; $index = 0; 1 } |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
704
|
|
54
|
12
|
|
|
|
|
22
|
else { $odds += $table->[ $index++ ]; $index %= @$table; 0 } |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
37
|
|
55
|
|
|
|
|
|
|
}, |
56
|
2
|
|
50
|
2
|
|
4
|
sub { $odds = $param{start}; $index = $param{index} // 0 } |
|
2
|
|
|
|
|
9
|
|
57
|
7
|
|
|
|
|
39
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
__END__ |