| 1 | package Crypt::Perl::Math; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Crypt::Perl::BigInt (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Crypt::Perl::RNG (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub ceil { | ||||||||||||||||||||||||||||
| 10 | 66 | ▶ | return int($_[0]) if $_[0] <= 0; | ||||||||||||||||||||||||||
|
Subroutine
ceil: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 66 | return int($_[0]) + int( !!($_[0] - int $_[0]) ); | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #limit is inclusive | ||||||||||||||||||||||||||||
| 16 | #cf. Python’s random.randint() | ||||||||||||||||||||||||||||
| 17 | sub randint { | ||||||||||||||||||||||||||||
| 18 | 324 | ▶ | my ($limit) = @_; | ||||||||||||||||||||||||||
|
Subroutine
randint: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 324 | my $limit_bit_count; | |||||||||||||||||||||||||||
| 21 | 324 | ▶ | if (ref($limit) && (ref $limit)->isa('Math::BigInt')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $limit and ref($limit)->isa("Math::BigInt")
MC/DC50%1/2
ref $limit and ref($limit)->isa("Math::BigInt")
ref $limit
ref($limit)->isa("Math::BigInt")
Truth table66%2/3
A and B
A= ref $limitB= ref($limit)->isa("Math::BigInt")
| |||||||||||||||||||||||||||||
| 22 | 304 | $limit_bit_count = length($limit->as_bin()) - 2; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #Is this ever needed?? | ||||||||||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||||||||||
| 27 | 20 | $limit_bit_count = length sprintf '%b', $limit; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 324 | my $rand; | |||||||||||||||||||||||||||
| 31 | 324 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 451 | $rand = Crypt::Perl::BigInt->from_bin( Crypt::Perl::RNG::bit_string($limit_bit_count) ); | |||||||||||||||||||||||||||
| 33 | } while $rand > $limit; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 324 | return $rand; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 8 | 1; | |||||||||||||||||||||||||||