line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Random::Set; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
67475
|
use strict; |
|
4
|
|
|
|
|
27
|
|
|
4
|
|
|
|
|
98
|
|
4
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
102
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1630
|
use Class::Utils qw(set_params); |
|
4
|
|
|
|
|
90879
|
|
|
4
|
|
|
|
|
69
|
|
7
|
4
|
|
|
4
|
|
274
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
889
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.06; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Constructor. |
12
|
|
|
|
|
|
|
sub new { |
13
|
5
|
|
|
5
|
1
|
4929
|
my ($class, @params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Create object. |
16
|
5
|
|
|
|
|
11
|
my $self = bless {}, $class; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Precision. |
19
|
5
|
|
|
|
|
15
|
$self->{'precision'} = 100; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Set. |
22
|
5
|
|
|
|
|
9
|
$self->{'set'} = []; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Process parameters. |
25
|
5
|
|
|
|
|
18
|
set_params($self, @params); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Check set. |
28
|
3
|
|
|
|
|
29
|
my $full = 0; |
29
|
3
|
|
|
|
|
3
|
foreach my $set_ar (@{$self->{'set'}}) { |
|
3
|
|
|
|
|
10
|
|
30
|
4
|
|
|
|
|
8
|
$full += $set_ar->[0]; |
31
|
|
|
|
|
|
|
} |
32
|
3
|
100
|
|
|
|
9
|
if ($full != 1) { |
33
|
1
|
|
|
|
|
2
|
err 'Bad set sum. Must be 1.'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Create set. |
37
|
2
|
|
|
|
|
5
|
$self->{'_set'} = []; |
38
|
2
|
|
|
|
|
3
|
foreach my $set_ar (@{$self->{'set'}}) { |
|
2
|
|
|
|
|
6
|
|
39
|
4
|
|
|
|
|
29
|
push @{$self->{'_set'}}, ($set_ar->[1]) |
40
|
4
|
|
|
|
|
5
|
x ($self->{'precision'} * $set_ar->[0]); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
7
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Get random result. |
47
|
|
|
|
|
|
|
sub get { |
48
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
49
|
1
|
|
|
|
|
2
|
my $index = int(rand(@{$self->{'_set'}})); |
|
1
|
|
|
|
|
26
|
|
50
|
1
|
|
|
|
|
6
|
return $self->{'_set'}->[$index]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |