line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Partition::Rand; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Partition a number into addition sequences |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
650
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
160
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
1
|
311
|
my $class = shift; |
15
|
1
|
|
|
|
|
3
|
my %args = @_; |
16
|
|
|
|
|
|
|
my $self = { |
17
|
|
|
|
|
|
|
top => $args{top} || 1, |
18
|
1
|
|
50
|
|
|
6
|
n => $args{n} || 2, |
|
|
|
50
|
|
|
|
|
19
|
|
|
|
|
|
|
}; |
20
|
1
|
|
|
|
|
2
|
bless $self, $class; |
21
|
1
|
|
|
|
|
2
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub choose { |
26
|
1
|
|
|
1
|
1
|
237
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
2
|
my @distribution; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
2
|
my $label = 0; |
31
|
1
|
|
|
|
|
6
|
my $top = $self->{top}; |
32
|
1
|
|
|
|
|
1
|
my $n = $self->{n}; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
for my $i ( 1 .. $n ) { |
35
|
3
|
|
|
|
|
30
|
my $curr = rand($top); |
36
|
3
|
|
|
|
|
4
|
my $next = abs( $top - $curr ); |
37
|
|
|
|
|
|
|
|
38
|
3
|
100
|
|
|
|
5
|
push @distribution, $i == $n ? $top : $next; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
3
|
$top = $curr; |
41
|
3
|
|
|
|
|
4
|
$label++; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
2
|
return \@distribution; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |