| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$stack_num > 0 and not exists $stack_nums{$stack_num}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | 1; | |||||||||||||||||||||||||||