line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Randr; |
2
|
2
|
|
|
2
|
|
42042
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
10
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
132
|
|
5
|
2
|
|
|
2
|
|
8
|
use Exporter 'import'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
667
|
|
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw/randr/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
4
|
|
|
4
|
1
|
2301
|
my ($class, %args) = @_; |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
|
|
9
|
my $rate = delete $args{rate}; |
14
|
4
|
|
|
|
|
8
|
my $digit = delete $args{digit}; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
|
|
17
|
bless { |
17
|
|
|
|
|
|
|
rate => $rate, |
18
|
|
|
|
|
|
|
digit => $digit, |
19
|
|
|
|
|
|
|
}, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
20000
|
|
|
20000
|
1
|
29695
|
sub rate { $_[0]->{rate} } |
23
|
30000
|
|
|
30000
|
1
|
46345
|
sub digit { $_[0]->{digit} } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub randr { |
26
|
90000
|
|
|
90000
|
1
|
435929
|
my ($self, $base, $rate, $digit); |
27
|
|
|
|
|
|
|
|
28
|
90000
|
100
|
|
|
|
169640
|
if (ref $_[0] eq __PACKAGE__) { |
29
|
40000
|
|
|
|
|
62574
|
($self, $base, $rate, $digit) = @_; |
30
|
40000
|
100
|
|
|
|
78482
|
$rate = $rate ? $rate : $self->rate; |
31
|
40000
|
100
|
|
|
|
86853
|
$digit = $digit ? $digit : $self->digit; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
50000
|
|
|
|
|
76465
|
($base, $rate, $digit) = @_; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
90000
|
|
100
|
|
|
181937
|
$rate ||= 10; |
38
|
|
|
|
|
|
|
|
39
|
90000
|
|
|
|
|
133709
|
my $splash = int( $base * ($rate/100) ); |
40
|
90000
|
100
|
|
|
|
200953
|
my $result = $base - $splash + rand($splash*2+1*($digit ? 0 : 1)); |
41
|
|
|
|
|
|
|
|
42
|
90000
|
100
|
|
|
|
150485
|
if ($digit) { |
43
|
30000
|
|
|
|
|
143373
|
return sprintf("%0.${digit}f", $result); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
60000
|
|
|
|
|
111665
|
return int($result); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |