| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Random::Weighted; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: get weighted random data |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
21653
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
39
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
196
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw( randomizer ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub randomizer { |
|
13
|
1
|
|
|
1
|
0
|
669
|
my $args = shift; |
|
14
|
1
|
|
|
|
|
2
|
my $total; |
|
15
|
1
|
|
|
|
|
5
|
$total += $_ for keys %$args; |
|
16
|
1
|
|
|
|
|
2
|
my $weight; |
|
17
|
1
|
|
|
|
|
2
|
my $count = 0; |
|
18
|
1
|
|
|
|
|
3
|
for my $set( keys %$args ) { |
|
19
|
1
|
|
|
|
|
1
|
my $result = $args->{$set}; |
|
20
|
1
|
|
|
|
|
4
|
for ( 1 .. $set ) { |
|
21
|
1
|
|
|
|
|
5
|
$weight->{$count++} = $result; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
return sub { |
|
25
|
1
|
|
|
1
|
|
49
|
my $rand = int(rand($total)); |
|
26
|
1
|
|
|
|
|
6
|
return $weight->{$rand}; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
1
|
|
|
|
|
6
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |