| 1 | package CellBIS::Random; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use List::SomeUtils qw(part); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Tool for Randomize characters in strings. | ||||||||||||||||||||||||||||
| 11 | 4 | our $VERSION = '0.3'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Constructor : | ||||||||||||||||||||||||||||
| 14 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 15 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | 4 | my $self = { | |||||||||||||||||||||||||||
| 18 | string => shift, | ||||||||||||||||||||||||||||
| 19 | result => 'null' | ||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||
| 21 | 4 | bless $self, $class; | |||||||||||||||||||||||||||
| 22 | 4 | return $self; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | sub set_string { | ||||||||||||||||||||||||||
|
Subroutine
set_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 4 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 27 | 4 | $self->{string} = $string; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub get_result { | ||||||||||||||||||||||||||
|
Subroutine
get_result: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 0 | return $self->{result}; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | sub random { | ||||||||||||||||||||||||||
|
Subroutine
random: called CC=33 SCAR=57.3
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 6 | my $arg_len = scalar @_; | |||||||||||||||||||||||||||
| 38 | 6 | my $string = ''; | |||||||||||||||||||||||||||
| 39 | 6 | my $count_odd = 0; | |||||||||||||||||||||||||||
| 40 | 6 | my $count_even = 0; | |||||||||||||||||||||||||||
| 41 | 6 | my $nested = 0; | |||||||||||||||||||||||||||
| 42 | 6 | ▶ | Carp::croak(q{Arguments is less than 2 or 3}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$arg_len == 2 or $arg_len >= 3
MC/DC0%0/2
$arg_len == 2 or $arg_len >= 3
$arg_len == 2
$arg_len >= 3
Truth table66%2/3
A or B
A= $arg_len == 2B= $arg_len >= 3
| |||||||||||||||||||||||||||||
| 43 | unless $arg_len == 2 or $arg_len >= 3; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 6 | ▶ | if (blessed($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 4 | ▶ | $string = $self->{string} if defined($self->{string}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 4 | ▶ | $string //= 'Is Empty'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$string //= "Is Empty"
MC/DC0%0/1
$string //= "Is Empty"
$string
Truth table50%1/2
A
A= $string
| |||||||||||||||||||||||||||||
| 48 | 4 | ▶ | ($count_odd, $count_even) = @_ if ($arg_len >= 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 4 | ▶ | ($string, $count_odd, $count_even) = @_ if ($arg_len >= 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | ($string, $count_odd, $count_even) = @_ if ($arg_len >= 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | my $result = $string; | |||||||||||||||||||||||||||
| 55 | 6 | my $i = 0; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # For Nested loop == 1 : | ||||||||||||||||||||||||||||
| 58 | 6 | ▶ | if ($nested == 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($count_odd != 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even != 0
MC/DC0%0/2
$count_odd != 0 and $count_even != 0
$count_odd != 0
$count_even != 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 60 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | while ($i < $count_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $result = $self->_union_odd_even($string); | |||||||||||||||||||||||||||
| 63 | 0 | $i++; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($count_odd != 0 and $count_even == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even == 0
MC/DC0%0/2
$count_odd != 0 and $count_even == 0
$count_odd != 0
$count_even == 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even == 0
| |||||||||||||||||||||||||||||
| 67 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | while ($i < $count_even) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | $result = $self->_union_even_odd($string); | |||||||||||||||||||||||||||
| 70 | 0 | $i++; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # For Nested loop == 2 : | ||||||||||||||||||||||||||||
| 76 | elsif ($nested == 2) { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($count_odd != 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even != 0
MC/DC0%0/2
$count_odd != 0 and $count_even != 0
$count_odd != 0
$count_even != 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | for ($i = 0; $i < $count_odd; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $result = $self->_union_odd_even($string); | |||||||||||||||||||||||||||
| 80 | 0 | $result = $self->loop_union_for_odd_even($count_even, $result, 'even_odd'); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($count_odd != 0 and $count_even == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even == 0
MC/DC0%0/2
$count_odd != 0 and $count_even == 0
$count_odd != 0
$count_even == 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even == 0
| |||||||||||||||||||||||||||||
| 84 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | while ($i < $count_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | $result = $self->_union_odd_even($string); | |||||||||||||||||||||||||||
| 87 | 0 | $i++; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($count_odd == 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd == 0 and $count_even != 0
MC/DC0%0/2
$count_odd == 0 and $count_even != 0
$count_odd == 0
$count_even != 0
Truth table0%0/3
A and B
A= $count_odd == 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 91 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | while ($i < $count_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | $result = $self->_union_even_odd($string); | |||||||||||||||||||||||||||
| 94 | 0 | $i++; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # For Nested loop == 0 : | ||||||||||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||||||||||
| 101 | 6 | ▶ | if ($count_odd != 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count_odd != 0 and $count_even != 0
MC/DC0%0/2
$count_odd != 0 and $count_even != 0
$count_odd != 0
$count_even != 0
Truth table33%1/3
A and B
A= $count_odd != 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 102 | 6 | $i = 0; | |||||||||||||||||||||||||||
| 103 | 6 | my $result1 = $self->loop_union_for_odd_even($count_odd, $result, 'odd_even'); | |||||||||||||||||||||||||||
| 104 | 6 | $result = $self->loop_union_for_odd_even($count_even, $result1, 'even_odd'); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 6 | ▶ | if ($count_odd != 0 and $count_even == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count_odd != 0 and $count_even == 0
MC/DC0%0/2
$count_odd != 0 and $count_even == 0
$count_odd != 0
$count_even == 0
Truth table33%1/3
A and B
A= $count_odd != 0B= $count_even == 0
| |||||||||||||||||||||||||||||
| 107 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 108 | 0 | $result = $self->loop_union_for_odd_even($count_odd, $result, 'odd_even'); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 6 | ▶ | if ($count_odd == 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count_odd == 0 and $count_even != 0
MC/DC0%0/2
$count_odd == 0 and $count_even != 0
$count_odd == 0
$count_even != 0
Truth table33%1/3
A and B
A= $count_odd == 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 111 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 112 | 0 | $result = $self->loop_union_for_odd_even($count_even, $result, 'even_odd'); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 6 | ▶ | $self->{'result'} = $result if blessed($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 6 | return $result; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 3 | ▶ | sub unrandom { | ||||||||||||||||||||||||||
|
Subroutine
unrandom: called CC=33 SCAR=58.2
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 3 | my $arg_len = scalar @_; | |||||||||||||||||||||||||||
| 122 | 3 | my $string = ''; | |||||||||||||||||||||||||||
| 123 | 3 | my $count_odd = 0; | |||||||||||||||||||||||||||
| 124 | 3 | my $count_even = 0; | |||||||||||||||||||||||||||
| 125 | 3 | my $nested = 0; | |||||||||||||||||||||||||||
| 126 | 3 | ▶ | Carp::croak(q{Arguments is less than 2 or 2}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$arg_len == 2 or $arg_len >= 3
MC/DC0%0/2
$arg_len == 2 or $arg_len >= 3
$arg_len == 2
$arg_len >= 3
Truth table66%2/3
A or B
A= $arg_len == 2B= $arg_len >= 3
| |||||||||||||||||||||||||||||
| 127 | unless $arg_len == 2 or $arg_len >= 3; | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 3 | ▶ | if (blessed($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 2 | ▶ | $string = $self->{string} if $self->{string}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 2 | ▶ | $string //= 'Is Empty'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$string //= "Is Empty"
MC/DC0%0/1
$string //= "Is Empty"
$string
Truth table50%1/2
A
A= $string
| |||||||||||||||||||||||||||||
| 132 | 2 | ▶ | ($count_odd, $count_even) = @_ if ($arg_len >= 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 2 | ▶ | ($string, $count_odd, $count_even) = @_ if ($arg_len >= 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | ($string, $count_odd, $count_even) = @_ if ($arg_len >= 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 3 | my $result = $string; | |||||||||||||||||||||||||||
| 139 | 3 | my $i = 0; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # For Nested loop == 1 : | ||||||||||||||||||||||||||||
| 142 | 3 | ▶ | if ($nested == 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($count_odd != 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even != 0
MC/DC0%0/2
$count_odd != 0 and $count_even != 0
$count_odd != 0
$count_even != 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 144 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | while ($i < $count_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | $result = $self->_reverse_union_odd_even($string); | |||||||||||||||||||||||||||
| 147 | 0 | $i++; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($count_odd != 0 and $count_even == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even == 0
MC/DC0%0/2
$count_odd != 0 and $count_even == 0
$count_odd != 0
$count_even == 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even == 0
| |||||||||||||||||||||||||||||
| 151 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | while ($i < $count_even) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | $result = $self->_reverse_union_even_odd($string); | |||||||||||||||||||||||||||
| 154 | 0 | $i++; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # For Nested loop == 2 : | ||||||||||||||||||||||||||||
| 160 | elsif ($nested == 2) { | ||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ($count_odd != 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even != 0
MC/DC0%0/2
$count_odd != 0 and $count_even != 0
$count_odd != 0
$count_even != 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 162 | # $i = 0; | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | for ($i = 0; $i < $count_odd; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | $result = $self->reverse_loop_union_for_odd_even($count_even, $string, 'even_odd'); | |||||||||||||||||||||||||||
| 165 | 0 | $result = $self->_reverse_union_odd_even($result); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if ($count_odd != 0 and $count_even == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd != 0 and $count_even == 0
MC/DC0%0/2
$count_odd != 0 and $count_even == 0
$count_odd != 0
$count_even == 0
Truth table0%0/3
A and B
A= $count_odd != 0B= $count_even == 0
| |||||||||||||||||||||||||||||
| 169 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | while ($i < $count_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | $result = $self->_reverse_union_odd_even($string); | |||||||||||||||||||||||||||
| 172 | 0 | $i++; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($count_odd == 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count_odd == 0 and $count_even != 0
MC/DC0%0/2
$count_odd == 0 and $count_even != 0
$count_odd == 0
$count_even != 0
Truth table0%0/3
A and B
A= $count_odd == 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 176 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 177 | 0 | ▶ | while ($i < $count_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | $result = $self->_reverse_union_even_odd($string); | |||||||||||||||||||||||||||
| 179 | 0 | $i++; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # For Nested loop == 0 : | ||||||||||||||||||||||||||||
| 185 | else { | ||||||||||||||||||||||||||||
| 186 | 3 | ▶ | if ($count_odd != 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count_odd != 0 and $count_even != 0
MC/DC0%0/2
$count_odd != 0 and $count_even != 0
$count_odd != 0
$count_even != 0
Truth table33%1/3
A and B
A= $count_odd != 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 187 | 3 | my $result1 = $self->reverse_loop_union_for_odd_even($count_even, $result, 'even_odd'); | |||||||||||||||||||||||||||
| 188 | 3 | $result = $self->reverse_loop_union_for_odd_even($count_odd, $result1, 'odd_even'); | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 3 | ▶ | if ($count_odd != 0 and $count_even == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count_odd != 0 and $count_even == 0
MC/DC0%0/2
$count_odd != 0 and $count_even == 0
$count_odd != 0
$count_even == 0
Truth table33%1/3
A and B
A= $count_odd != 0B= $count_even == 0
| |||||||||||||||||||||||||||||
| 191 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 192 | 0 | $result = $self->reverse_loop_union_for_odd_even($count_odd, $string, 'odd_even'); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | 3 | ▶ | if ($count_odd == 0 and $count_even != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count_odd == 0 and $count_even != 0
MC/DC0%0/2
$count_odd == 0 and $count_even != 0
$count_odd == 0
$count_even != 0
Truth table33%1/3
A and B
A= $count_odd == 0B= $count_even != 0
| |||||||||||||||||||||||||||||
| 195 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 196 | 0 | $result = $self->reverse_loop_union_for_odd_even($count_even, $string, 'even_odd'); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 3 | ▶ | $self->{'result'} = $result if blessed($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 3 | return $result; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | ############################################################################################# | ||||||||||||||||||||||||||||
| 204 | # UTILITIES : | ||||||||||||||||||||||||||||
| 205 | ############################################################################################# | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 12 | ▶ | sub loop_union_for_odd_even { | ||||||||||||||||||||||||||
|
Subroutine
loop_union_for_odd_even: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 208 | 12 | my ($self, $count_loop, $string, $type) = @_; | |||||||||||||||||||||||||||
| 209 | 12 | my $result = $string; | |||||||||||||||||||||||||||
| 210 | 12 | my $i = 0; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 12 | ▶ | if ($type eq 'odd_even') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 6 | ▶ | while ($i < $count_loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 12 | $result = $self->_union_odd_even($result); | |||||||||||||||||||||||||||
| 215 | 12 | $i++; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | 12 | ▶ | if ($type eq 'even_odd') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 6 | ▶ | while ($i < $count_loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 18 | $result = $self->_union_even_odd($result); | |||||||||||||||||||||||||||
| 221 | 18 | $i++; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 12 | return $result; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 6 | ▶ | sub reverse_loop_union_for_odd_even { | ||||||||||||||||||||||||||
|
Subroutine
reverse_loop_union_for_odd_even: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 229 | 6 | my ($self, $count_loop, $string, $type) = @_; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 6 | my $result = $string; | |||||||||||||||||||||||||||
| 232 | 6 | my $i = 0; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 6 | ▶ | if ($type eq 'odd_even') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 3 | ▶ | while ($i < $count_loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 6 | $result = $self->_reverse_union_odd_even($result); | |||||||||||||||||||||||||||
| 237 | 6 | $i++; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | 6 | ▶ | if ($type eq 'even_odd') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 3 | ▶ | while ($i < $count_loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 9 | $result = $self->_reverse_union_even_odd($result); | |||||||||||||||||||||||||||
| 243 | 9 | $i++; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 6 | return $result; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 6 | ▶ | sub _reverse_union_odd_even { | ||||||||||||||||||||||||||
|
Subroutine
_reverse_union_odd_even: called CC=9 SCAR=24.4
| |||||||||||||||||||||||||||||
| 251 | 6 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 6 | my @arr_str = $self->_split_blen($string, 1); | |||||||||||||||||||||||||||
| 254 | 6 | my $i = 0; | |||||||||||||||||||||||||||
| 255 | 6 | ▶ | my ($even, $odd) = part {$i++ % 2} @arr_str; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 256 | 6 | my $str_odd = join '', @{$odd}; | |||||||||||||||||||||||||||
| 257 | 6 | my $str_even = join '', @{$even}; | |||||||||||||||||||||||||||
| 258 | 6 | my $len_odd = length $str_odd; | |||||||||||||||||||||||||||
| 259 | 6 | my $len_even = length $str_even; | |||||||||||||||||||||||||||
| 260 | 6 | my $for_odd = substr $string, 0, $len_odd; | |||||||||||||||||||||||||||
| 261 | 6 | my $for_even = substr $string, $len_odd, $len_even; | |||||||||||||||||||||||||||
| 262 | 6 | my @arr_even = $self->_split_blen($for_even, 1); | |||||||||||||||||||||||||||
| 263 | 6 | my @arr_odd = $self->_split_blen($for_odd, 1); | |||||||||||||||||||||||||||
| 264 | 6 | my $result = ''; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 6 | ▶ | if ($len_even > $len_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 6 | $i = 0; | |||||||||||||||||||||||||||
| 268 | 6 | ▶ | while ($i < $len_even) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 66 | ▶ | $result .= $arr_even[$i] if exists $arr_even[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 66 | ▶ | $result .= $arr_odd[$i] if exists $arr_odd[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 66 | $i++; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | 6 | ▶ | if ($len_even == $len_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 276 | 0 | ▶ | while ($i < $len_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $result .= $arr_even[$i] if exists $arr_even[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | ▶ | $result .= $arr_odd[$i] if exists $arr_odd[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 0 | $i++; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | 6 | return $result; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 9 | ▶ | sub _reverse_union_even_odd { | ||||||||||||||||||||||||||
|
Subroutine
_reverse_union_even_odd: called CC=9 SCAR=24.4
| |||||||||||||||||||||||||||||
| 286 | 9 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 9 | my @arr_str = $self->_split_blen($string, 1); | |||||||||||||||||||||||||||
| 289 | 9 | my $i = 0; | |||||||||||||||||||||||||||
| 290 | 9 | ▶ | my ($even, $odd) = part {$i++ % 2} @arr_str; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 291 | 9 | my $str_even = join '', @{$even}; | |||||||||||||||||||||||||||
| 292 | 9 | my $str_odd = join '', @{$odd}; | |||||||||||||||||||||||||||
| 293 | 9 | my $len_even = length $str_even; | |||||||||||||||||||||||||||
| 294 | 9 | my $len_odd = length $str_odd; | |||||||||||||||||||||||||||
| 295 | 9 | my $for_even = substr $string, 0, $len_even; | |||||||||||||||||||||||||||
| 296 | 9 | my $for_odd = substr $string, $len_even, $len_odd; | |||||||||||||||||||||||||||
| 297 | 9 | my @arr_even = $self->_split_blen($for_even, 1); | |||||||||||||||||||||||||||
| 298 | 9 | my @arr_odd = $self->_split_blen($for_odd, 1); | |||||||||||||||||||||||||||
| 299 | 9 | my $result = ''; | |||||||||||||||||||||||||||
| 300 | 9 | ▶ | if ($len_even > $len_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 9 | $i = 0; | |||||||||||||||||||||||||||
| 302 | 9 | ▶ | while ($i < $len_even) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 99 | ▶ | $result .= $arr_even[$i] if exists $arr_even[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 99 | ▶ | $result .= $arr_odd[$i] if exists $arr_odd[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | 99 | $i++; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | 9 | ▶ | if ($len_even == $len_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 310 | 0 | ▶ | while ($i < $len_odd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | $result .= $arr_even[$i] if exists $arr_even[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $result .= $arr_odd[$i] if exists $arr_odd[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 0 | $i++; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | 9 | return $result; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 12 | ▶ | sub _union_odd_even { | ||||||||||||||||||||||||||
|
Subroutine
_union_odd_even: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 320 | 12 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 12 | my $odd_char = $self->_odd_even_char('odd', $string); | |||||||||||||||||||||||||||
| 323 | 12 | my $even_char = $self->_odd_even_char('even', $string); | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 12 | return $odd_char . $even_char; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 18 | ▶ | sub _union_even_odd { | ||||||||||||||||||||||||||
|
Subroutine
_union_even_odd: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 329 | 18 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 18 | my $even_char = $self->_odd_even_char('even', $string); | |||||||||||||||||||||||||||
| 332 | 18 | my $odd_char = $self->_odd_even_char('odd', $string); | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 18 | return $even_char . $odd_char; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 60 | ▶ | sub _odd_even_char { | ||||||||||||||||||||||||||
|
Subroutine
_odd_even_char: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 338 | 60 | my ($self, $type, $string) = @_; | |||||||||||||||||||||||||||
| 339 | 60 | my $data = ''; | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 60 | my @arr_str = $self->_split_blen($string, 1); | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 60 | my @result = (); | |||||||||||||||||||||||||||
| 344 | 60 | my @pre_data = (); | |||||||||||||||||||||||||||
| 345 | 60 | my @pre_data1 = (); | |||||||||||||||||||||||||||
| 346 | 60 | my @data = (); | |||||||||||||||||||||||||||
| 347 | 60 | ▶ | if ($type eq 'odd') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 30 | @result = grep {$_ % 2 == 1} 0 .. $#arr_str; | |||||||||||||||||||||||||||
| 349 | 30 | @pre_data1 = map {$pre_data[$_] => $arr_str[$result[$_]]} 0 .. $#result; | |||||||||||||||||||||||||||
| 350 | 30 | @data = grep (defined, @pre_data1); | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | 60 | ▶ | if ($type eq 'even') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 30 | @result = grep {$_ % 2 == 0} 0 .. $#arr_str; | |||||||||||||||||||||||||||
| 354 | 30 | @pre_data1 = map {$pre_data[$_] => $arr_str[$result[$_]]} 0 .. $#result; | |||||||||||||||||||||||||||
| 355 | 30 | @data = grep (defined, @pre_data1); | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | 60 | $data = join '', @data; | |||||||||||||||||||||||||||
| 358 | 60 | return $data; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | ▶ | sub _split_bchar { | ||||||||||||||||||||||||||
|
Subroutine
_split_bchar: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 362 | 0 | my ($self, $string, $delimiter) = @_; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | # Split : | ||||||||||||||||||||||||||||
| 365 | 0 | my @split = split /$delimiter/, $string; | |||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # Return : | ||||||||||||||||||||||||||||
| 368 | 0 | return @split; | |||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 105 | ▶ | sub _split_blen { | ||||||||||||||||||||||||||
|
Subroutine
_split_blen: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 372 | 105 | my ($self, $string, $length) = @_; | |||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | # Split : | ||||||||||||||||||||||||||||
| 375 | 105 | my $len = "." x $length; | |||||||||||||||||||||||||||
| 376 | 105 | my @data = grep {length > 0} split(/($len)/, $string); | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | # Return : | ||||||||||||||||||||||||||||
| 379 | 105 | return @data; | |||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 4 | 1; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =encoding utf8 | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =head1 NAME | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | CellBIS::Random - Tool for Randomize characters in strings. | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | my $rand = CellBIS::Random->new(); | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | my $string = 'my_string_test_random'; | ||||||||||||||||||||||||||||
| 397 | $rand->set_string($random); | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | my $random = $rand->random(2, 3); | ||||||||||||||||||||||||||||
| 400 | print 'Random : ', $random, "\r"; #-> ynsn_dtgso__tmrtrmaei | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | my $unrandom = $rand->unrandom(2, 3); | ||||||||||||||||||||||||||||
| 403 | print 'Unrandom : ', $unrandom, "\r"; #-> my_string_test_random | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | The purpose of this module is to randomize characters in strings. | ||||||||||||||||||||||||||||
| 408 | Before a random or unrandom character (extract from random), the string | ||||||||||||||||||||||||||||
| 409 | will be converted to an array to get an odd/even number of key array. | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | =head1 METHODS | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | There is four methods C<set_string>, C<get_result>, C<random> and C<unrandom>. | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | Specifically for C<random> and C<unrandom> methods, you can use two or three arguments. | ||||||||||||||||||||||||||||
| 416 | If using Object Oriented, you can use 2 arguments. But if using Procedural, you can use 3 arguments. | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | # Object Oriented | ||||||||||||||||||||||||||||
| 419 | # Arguments : <number_of_random_odd>, <number_of_random_even> | ||||||||||||||||||||||||||||
| 420 | $rand->random(2, 3); | ||||||||||||||||||||||||||||
| 421 | $rand->unrandom(2, 3); | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | # Or Arguments : <your_string_to_random>, <number_of_random_odd>, <number_of_random_even> | ||||||||||||||||||||||||||||
| 424 | $rand->random('your string to random', 2, 3); | ||||||||||||||||||||||||||||
| 425 | $rand->unrandom('result of random to extract', 2, 3); | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | # Procedural | ||||||||||||||||||||||||||||
| 428 | # Arguemnts : <your_string_to_random>, <number_of_random_odd>, <number_of_random_even> | ||||||||||||||||||||||||||||
| 429 | CellBIS::Random->random('your string to random', 2, 3); | ||||||||||||||||||||||||||||
| 430 | CellBIS::Random->unrandom('result of random to extract', 2, 3); | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =head2 set_string | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | Method to set up string for Random action. | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =head2 get_result | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | Method to get result of random character and Extract result of random. | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =head2 random | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | With C<set_string> : | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | my $string = 'my string here'; | ||||||||||||||||||||||||||||
| 447 | $rand->set_string($string); | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | my $result_random = $rand->random(2, 3); | ||||||||||||||||||||||||||||
| 450 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | Without C<set_string> : | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | my $result_random = $rand->random('my string here', 2, 3); | ||||||||||||||||||||||||||||
| 455 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | =head2 unrandom | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | With C<set_string> : | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | $rand->set_string($result_random); | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | my $result_unrandom = $rand->unrandom(2, 3); | ||||||||||||||||||||||||||||
| 464 | print "Extract Random Result : $result_unrandom \n"; | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | Without C<set_string> : | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | my $result_unrandom = $rand->unrandom($rand->{result}, 2, 3); | ||||||||||||||||||||||||||||
| 469 | print "Extract Random Result : $result_unrandom \n"; | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | Example to using Procedural and Object Oriented | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | =head2 Procedural | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | Case 1 | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | my $result_random = CellBIS::Random->random('my string here', 2, 3); | ||||||||||||||||||||||||||||
| 482 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | my $extract_random = CellBIS::Random->unrandom($result_random, 2, 3); | ||||||||||||||||||||||||||||
| 485 | print "Extract Random Result : $extract_random \n"; | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | Case 2 | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | my $rand = CellBIS::Random->new(); | ||||||||||||||||||||||||||||
| 492 | my $result_random = $rand->random('my string here', 2, 3); | ||||||||||||||||||||||||||||
| 493 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | my $extract_random = $rand->unrandom($result_random, 2, 3); | ||||||||||||||||||||||||||||
| 496 | print "Extract Random Result : $extract_random \n"; | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | =head2 Object Oriented | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | Case 1 | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | my $rand = CellBIS::Random->new(); | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | # For Random | ||||||||||||||||||||||||||||
| 507 | $rand->set_string('my string here'); | ||||||||||||||||||||||||||||
| 508 | $rand->random(2, 3); | ||||||||||||||||||||||||||||
| 509 | my $result_random = $rand->get_result(); | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | ===================================================== | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | # For Extract Random | ||||||||||||||||||||||||||||
| 516 | $rand->set_string($result_random); | ||||||||||||||||||||||||||||
| 517 | $rand->unrandom(2, 3); | ||||||||||||||||||||||||||||
| 518 | my $extract_random = $rand->get_result(); | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | print "Extract Random Result : $extract_random \n"; | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | Case 2 | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | my $rand = CellBIS::Random->new(); | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | # For Random | ||||||||||||||||||||||||||||
| 529 | $rand->set_string('my string here'); | ||||||||||||||||||||||||||||
| 530 | my $result_random = $rand->random('my string here', 2, 3); | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | ===================================================== | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | # For Extract Random | ||||||||||||||||||||||||||||
| 537 | my $extract_random = $rand->unrandom($result_random, 2, 3); | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | print "Extract Random Result : $extract_random \n"; | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | Case 3 | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | use CellBIS::Random; | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | my $rand = CellBIS::Random->new(); | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | # For Random | ||||||||||||||||||||||||||||
| 548 | my $result_random = $rand->random('my string here', 2, 3); | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | print "Random Result : $result_random \n"; | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | ===================================================== | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | # For Extract Random | ||||||||||||||||||||||||||||
| 555 | my $extract_random = $rand->unrandom($result_random, 2, 3); | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | print "Extract Random Result : $extract_random \n"; | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | Achmad Yusri Afandi, E<lt>yusrideb@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | Copyright (C) 2018 by Achmad Yusri Afandi | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | This program is free software, you can redistribute it and/or modify it under the terms of | ||||||||||||||||||||||||||||
| 569 | the Artistic License version 2.0. | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | =cut | ||||||||||||||||||||||||||||