blib/lib/VANAMBURG/RandomNumbers.pm

filter: Statementstmt 21.0% 4 / 19 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 1 / 3 Podpod 100% 2 / 2 totaltotal 20.0% 7 / 35 CC 5 SCAR 25.9
CC
5
Cov
14%
random_stacknumbers
20.0
number_between
6.0
BEGIN
1.0
CRAP 13.3
↑ Summary lib/VANAMBURG/Card.pm »
1 package VANAMBURG::RandomNumbers;
2 1 ▶use List::Util qw/shuffle/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4  
5 =head1 VANAMBURG::RandomNumbers
6  
7 Random number generators specifically useful for card magic
8 simulations.
9  
10 =cut
11  
12 =head2 random_stacknumbers
13  
14 my @ten_selections = $random_stacknumbers(10);
15  
16 Returns an array of numbers having the value of 1 through 52.
17  
18 =cut
19  
20 0 ▶sub random_stacknumbers {
Subroutine random_stacknumbers: not called CC=4 SCAR=30.0
Pod documented
21 0 my ( $class, $number_of_numbers ) = @_;
22  
23 0 my %stack_nums;
24 0 ▶ while ( keys %stack_nums < $number_of_numbers) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %stack_nums < $number_of_numbers) 0 0 0
25 0 my $stack_num;
26 0 while (1) {
27 0 $stack_num = int( rand(53) );
28 0 ▶ if ( $stack_num > 0 && !exists $stack_nums{$stack_num} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stack_num > 0 and not exists $stack_nums{$stack_num}) 0 0 0
Condition0%0/3
$stack_num > 0 and not exists $stack_nums{$stack_num}
!ll&&!rl&&r
000
MC/DC0%0/2
$stack_num > 0 and not exists $stack_nums{$stack_num}
$stack_num > 0 not exists $stack_nums{$stack_num}
Truth table0%0/3
A and not(B)
A= $stack_num > 0B= not exists $stack_nums{$stack_num}
ABresult
0X0
100
111
29 0 $stack_nums{$stack_num} = 1;
30 0 last;
31 }# end if
32 }# end while
33 }# end while
34 0 my @results = keys %stack_nums;
35 0 return shuffle @results;
36 }
37  
38  
39 =head2 number_between
40  
41 my $number = number_between(1,10);
42
43 =cut
44  
45 0 ▶sub number_between {
Subroutine number_between: not called CC=2 SCAR=17.9
Pod documented
46 0 my ( $low, $high ) = @_;
47 0 while (1) {
48 0 my $deck_num = int( rand( $high + 1 ) );
49 0 ▶ return $deck_num if ( $deck_num >= $low );
Branch: 1 branch
BranchTrueFalseTotal
if $deck_num >= $low 0 0 0
50 }
51 }
52  
53 1 1;
↑ Summary lib/VANAMBURG/Card.pm »