line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Perl::Math; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
699
|
use strict; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
323
|
|
4
|
10
|
|
|
10
|
|
72
|
use warnings; |
|
10
|
|
|
|
|
41
|
|
|
10
|
|
|
|
|
305
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
85
|
use Crypt::Perl::BigInt (); |
|
10
|
|
|
|
|
87
|
|
|
10
|
|
|
|
|
175
|
|
7
|
10
|
|
|
10
|
|
4206
|
use Crypt::Perl::RNG (); |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
1685
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub ceil { |
10
|
444
|
50
|
|
444
|
0
|
12337
|
return int($_[0]) if $_[0] <= 0; |
11
|
|
|
|
|
|
|
|
12
|
444
|
|
|
|
|
2178
|
return int($_[0]) + int( !!($_[0] - int $_[0]) ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#limit is inclusive |
16
|
|
|
|
|
|
|
#cf. Python’s random.randint() |
17
|
|
|
|
|
|
|
sub randint { |
18
|
311
|
|
|
311
|
0
|
23561
|
my ($limit) = @_; |
19
|
|
|
|
|
|
|
|
20
|
311
|
|
|
|
|
644
|
my $limit_bit_count; |
21
|
311
|
100
|
66
|
|
|
3941
|
if (ref($limit) && (ref $limit)->isa('Math::BigInt')) { |
22
|
291
|
|
|
|
|
1733
|
$limit_bit_count = length($limit->as_bin()) - 2; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#Is this ever needed?? |
26
|
|
|
|
|
|
|
else { |
27
|
20
|
|
|
|
|
69
|
$limit_bit_count = length sprintf '%b', $limit; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
311
|
|
|
|
|
12124
|
my $rand; |
31
|
311
|
|
|
|
|
870
|
do { |
32
|
436
|
|
|
|
|
528208
|
$rand = Crypt::Perl::BigInt->from_bin( Crypt::Perl::RNG::bit_string($limit_bit_count) ); |
33
|
|
|
|
|
|
|
} while $rand > $limit; |
34
|
|
|
|
|
|
|
|
35
|
311
|
|
|
|
|
1432157
|
return $rand; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |