blib/lib/Venus/Random.pm

filter: Statementstmt 99.4% 186 / 187 Branchbran 73.8% 31 / 42 Conditioncond 55.8% 38 / 68 MC/DCmcdc 23.6% 9 / 38 Subroutinesub 100% 46 / 46 Podpod 95.2% 40 / 42 totaltotal 82.7% 350 / 423 CC 50 SCAR 14.6
CC
50
Cov
86%
range
12.0
float
10.7
nonzero
7.2
CRAP 4.3
« blib/lib/Venus/Match.pm ↑ Summary blib/lib/Venus/Array.pm »
1 package Venus::Random;
2  
3 2 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 2 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 2 base 'Venus::Kind::Utility';
15  
16 # INTEGRATES
17  
18 2 with 'Venus::Role::Valuable';
19 2 with 'Venus::Role::Buildable';
20 2 with 'Venus::Role::Accessible';
21  
22 # STATE
23  
24 2 state $ORIG_SEED = srand;
25 2 state $SELF_SEED = substr(((time ^ $$) ** 2), 0, length($ORIG_SEED));
26 2 srand $ORIG_SEED;
27  
28 # BUILDERS
29  
30 126 ▶sub build_self {
Subroutine build_self: called CC=1 SCAR=0.0
Pod undocumented
31 126 my ($self, $data) = @_;
32  
33 126 $self->reseed($self->value);
34  
35 126 return $self;
36 }
37  
38 # METHODS
39  
40 1050 ▶sub alphanumeric {
Subroutine alphanumeric: called CC=1 SCAR=0.0
Pod documented
41 1050 my ($self) = @_;
42  
43 1050 my $code = $self->select(['digit', 'letter']);
44  
45 1050 return $self->$code;
46 }
47  
48 102 ▶sub alphanumerics {
Subroutine alphanumerics: called CC=2 SCAR=7.1
Pod documented
49 102 my ($self, $times) = @_;
50  
51 102 ▶ my $result = $self->collect($times || 1, 'alphanumeric');
Condition50%1/2
$times || 1
l!l
1020
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
52  
53 102 return $result;
54 }
55  
56 42 ▶sub base64 {
Subroutine base64: called CC=1 SCAR=0.0
Pod documented
57 42 my ($self) = @_;
58  
59 42 require Digest::SHA;
60 42 require MIME::Base64;
61  
62 42 my $result = $self->token;
63  
64 42 $result = MIME::Base64::encode_base64(Digest::SHA::sha256($result));
65  
66 42 chomp $result;
67  
68 42 return $result;
69 }
70  
71 307 ▶sub bit {
Subroutine bit: called CC=1 SCAR=0.0
Pod documented
72 307 my ($self) = @_;
73  
74 307 return $self->select([1, 0]);
75 }
76  
77 51 ▶sub bits {
Subroutine bits: called CC=2 SCAR=7.1
Pod documented
78 51 my ($self, $times) = @_;
79  
80 51 ▶ my $result = $self->collect($times || 1, 'bit');
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
81  
82 51 return $result;
83 }
84  
85 51 ▶sub boolean {
Subroutine boolean: called CC=1 SCAR=0.0
Pod documented
86 51 my ($self) = @_;
87  
88 51 return $self->select([true, false]);
89 }
90  
91 306 ▶sub byte {
Subroutine byte: called CC=1 SCAR=0.0
Pod documented
92 306 my ($self) = @_;
93  
94 306 return chr(int($self->pick * 256));
95 }
96  
97 51 ▶sub bytes {
Subroutine bytes: called CC=2 SCAR=7.1
Pod documented
98 51 my ($self, $times) = @_;
99  
100 51 ▶ my $result = $self->collect($times || 1, 'byte');
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
101  
102 51 return $result;
103 }
104  
105 918 ▶sub character {
Subroutine character: called CC=1 SCAR=0.0
Pod documented
106 918 my ($self) = @_;
107  
108 918 my $code = $self->select(['digit', 'letter', 'symbol']);
109  
110 918 return $self->$code;
111 }
112  
113 51 ▶sub characters {
Subroutine characters: called CC=2 SCAR=7.1
Pod documented
114 51 my ($self, $times) = @_;
115  
116 51 ▶ my $result = $self->collect($times || 1, 'character');
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
117  
118 51 return $result;
119 }
120  
121 769 ▶sub collect {
Subroutine collect: called CC=1 SCAR=0.0
Pod documented
122 769 my ($self, $times, $code, @args) = @_;
123  
124 769 return scalar($self->repeat($times, $code, @args));
125 }
126  
127 2 ▶sub default {
Subroutine default: called CC=1 SCAR=0.0
Pod undocumented
128 2 state $default = $SELF_SEED;
129  
130 2 return $default++;
131 }
132  
133 21 ▶sub digest {
Subroutine digest: called CC=1 SCAR=0.0
Pod documented
134 21 my ($self) = @_;
135  
136 21 my $result = $self->token;
137  
138 21 return $result;
139 }
140  
141 1915 ▶sub digit {
Subroutine digit: called CC=1 SCAR=0.0
Pod documented
142 1915 my ($self) = @_;
143  
144 1915 return int($self->pick(10));
145 }
146  
147 51 ▶sub digits {
Subroutine digits: called CC=2 SCAR=7.1
Pod documented
148 51 my ($self, $times) = @_;
149  
150 51 ▶ my $result = $self->collect($times || 1, 'digit');
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
151  
152 51 return $result;
153 }
154  
155 306 ▶sub float {
Subroutine float: called CC=7 SCAR=23.7
Pod documented
156 306 my ($self, $place, $from, $upto) = @_;
157  
158 306 ▶ $from //= 0;
Condition100%2/2
$from //= 0
l!l
102204
MC/DC100%1/1
$from //= 0
$from
Truth table100%2/2
A
A= $from
Aresult
11
00
159 306 ▶ $upto //= $self->number;
Condition66%2/3
$upto //= $self->number
l!l&&r!l&&!r
1022040
MC/DC0%0/2
$upto //= $self->number
$upto $self->number
Truth table66%2/3
A //= B
A= $uptoB= $self->number
ABresult
1X1
011
000
160  
161 306 ▶ my $tmp; $tmp = $from and $from = $upto and $upto = $tmp if $from > $upto;
Branch: 1 branch
BranchTrueFalseTotal
if $from > $upto 0 306 306
Condition11%1/9
$from > $upto && (($tmp = $from) && ($from = $upto) && ($upto = $tmp))
!ll&&!rl&&r
30600
$tmp = $from and $from = $upto and $upto = $tmp
!ll&&!rl&&r
000
$tmp = $from and $from = $upto
!ll&&!rl&&r
000
MC/DC0%0/4
$from > $upto && (($tmp = $from) && ($from = $upto) && ($upto = $tmp))
$from > $upto $tmp = $from $from = $upto $upto = $tmp
Truth table0%0/5
A && B and C and D
A= $from > $uptoB= $tmp = $fromC= $from = $uptoD= $upto = $tmp
ABCDresult
0XXX0
10XX0
110X0
11100
11111
162  
163 306 ▶ $place //= $self->nonzero;
Condition66%2/3
$place //= $self->nonzero
l!l&&r!l&&!r
1531530
MC/DC0%0/2
$place //= $self->nonzero
$place $self->nonzero
Truth table66%2/3
A //= B
A= $placeB= $self->nonzero
ABresult
1X1
011
000
164  
165 306 return sprintf("%.${place}f", $from + rand() * ($upto - $from));
166 }
167  
168 306 ▶sub hexdecimal {
Subroutine hexdecimal: called CC=1 SCAR=0.0
Pod documented
169 306 my ($self) = @_;
170  
171 306 state $hexdecimal = [0..9, 'a'..'f'];
172  
173 306 return $self->select($hexdecimal);
174 }
175  
176 51 ▶sub hexdecimals {
Subroutine hexdecimals: called CC=2 SCAR=7.1
Pod documented
177 51 my ($self, $times) = @_;
178  
179 51 ▶ my $result = $self->collect($times || 1, 'hexdecimal');
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
180  
181 51 return $result;
182 }
183  
184 21 ▶sub id {
Subroutine id: called CC=2 SCAR=6.9
Pod documented
185 21 my ($self) = @_;
186  
187 21 state $instance = 0;
188  
189 21 state $previous = '';
190  
191 21 my $current = time;
192  
193 21 ▶ if ($current eq $previous) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current eq $previous) { } 20 1 21
194 20 $instance++;
195 }
196 else {
197 1 $instance = 0;
198 1 $previous = $current;
199 }
200  
201 21 my $result = $current . $instance . $$;
202  
203 21 return $result;
204 }
205  
206 1384 ▶sub letter {
Subroutine letter: called CC=1 SCAR=0.0
Pod documented
207 1384 my ($self) = @_;
208  
209 1384 my $code = $self->select(['uppercased', 'lowercased']);
210  
211 1384 return $self->$code;
212 }
213  
214 51 ▶sub letters {
Subroutine letters: called CC=2 SCAR=7.1
Pod documented
215 51 my ($self, $times) = @_;
216  
217 51 ▶ my $result = $self->collect($times || 1, 'letter');
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
218  
219 51 return $result;
220 }
221  
222 751 ▶sub lowercased {
Subroutine lowercased: called CC=1 SCAR=0.0
Pod documented
223 751 my ($self) = @_;
224  
225 751 return lc(chr($self->range(97, 122)));
226 }
227  
228 10487 ▶sub pick {
Subroutine pick: called CC=2 SCAR=6.9
Pod documented
229 10487 my ($self, $data) = @_;
230  
231 10487 ▶ return $data ? rand($data) : rand;
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 10051 436 10487
232 }
233  
234 3 ▶sub nonce {
Subroutine nonce: called CC=1 SCAR=0.0
Pod documented
235 3 my ($self) = @_;
236  
237 3 my $result = $self->collect(10, 'alphanumeric');
238  
239 3 return $result;
240 }
241  
242 385 ▶sub nonzero {
Subroutine nonzero: called CC=7 SCAR=19.8
Pod documented
243 385 my ($self, $code, @args) = @_;
244  
245 385 ▶ $code ||= 'digit';
Condition100%2/2
$code ||= "digit"
l!l
153232
MC/DC100%1/1
$code ||= "digit"
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
246  
247 385 my $value = $self->$code(@args);
248  
249 return
250 385 ▶ ($value < 0 && $value > -1) ? ($value + -1)
Branch: 3 branches
BranchTrueFalseTotal
$value < 0 && $value > -1 ? : 0 385 385
$value < 1 && $value > 0 ? : 51 334 385
$value == 0 ? : 28 306 334
Condition66%4/6
$value < 0 and $value > -1
!ll&&!rl&&r
38500
$value < 1 and $value > 0
!ll&&!rl&&r
3062851
MC/DC0%0/2
$value < 0 and $value > -1
$value < 0 $value > -1
MC/DC100%2/2
$value < 1 and $value > 0
$value < 1 $value > 0
Truth table33%1/3
A and B
A= $value < 0B= $value > -1
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $value < 1B= $value > 0
ABresult
0X0
100
111
251 : (($value < 1 && $value > 0) ? ($value + 1)
252 : ($value == 0 ? $self->nonzero : $value));
253 }
254  
255 765 ▶sub number {
Subroutine number: called CC=5 SCAR=16.2
Pod documented
256 765 my ($self, $from, $upto) = @_;
257  
258 765 ▶ $upto //= 0;
Condition100%2/2
$upto //= 0
l!l
408357
MC/DC100%1/1
$upto //= 0
$upto
Truth table100%2/2
A
A= $upto
Aresult
11
00
259 765 ▶ $from //= $self->digit;
Condition66%2/3
$from //= $self->digit
l!l&&r!l&&!r
4593060
MC/DC0%0/2
$from //= $self->digit
$from $self->digit
Truth table66%2/3
A //= B
A= $fromB= $self->digit
ABresult
1X1
011
000
260  
261 765 ▶ return $self->range($from, $upto) if $upto;
Branch: 1 branch
BranchTrueFalseTotal
if $upto 408 357 765
262  
263 357 ▶ return int($self->pick(10 ** ($from > 9 ? 9 : $from) -1));
Branch: 1 branch
BranchTrueFalseTotal
$from > 9 ? : 0 357 357
264 }
265  
266 51 ▶sub numbers {
Subroutine numbers: called CC=2 SCAR=7.1
Pod documented
267 51 my ($self, $times) = @_;
268  
269 51 ▶ my $result = $self->collect($times || 1, 'number', 1, 9);
Condition50%1/2
$times || 1
l!l
510
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
270  
271 51 return $result;
272 }
273  
274 51 ▶sub password {
Subroutine password: called CC=3 SCAR=11.3
Pod documented
275 51 my ($self, $ccount) = @_;
276  
277 51 ▶ $ccount ||= 16;
Condition50%1/2
$ccount ||= 16
l!l
051
MC/DC0%0/1
$ccount ||= 16
$ccount
Truth table50%1/2
A
A= $ccount
Aresult
11
00
278  
279 51 ▶ my $scount = $ccount > 8 ? $ccount / 8 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ccount > 8 ? : 51 0 51
280  
281 51 my $result = $self->shuffle(join '', $self->alphanumerics($ccount - $scount), $self->symbols($scount));
282  
283 51 return $result;
284 }
285  
286 6916 ▶sub range {
Subroutine range: called CC=9 SCAR=24.8
Pod documented
287 6916 my ($self, $from, $upto) = @_;
288  
289 6916 ▶ return 0 if !defined $from;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from 0 6916 6916
290 6916 ▶ return 0 if !defined $upto && $from == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $upto and $from == 0 0 6916 6916
Condition33%1/3
not defined $upto and $from == 0
!ll&&!rl&&r
691600
MC/DC0%0/2
not defined $upto and $from == 0
not defined $upto $from == 0
Truth table33%1/3
not(A) and B
A= not defined $uptoB= $from == 0
ABresult
0X0
100
111
291  
292 6916 ▶ return $from if $from == $upto;
Branch: 1 branch
BranchTrueFalseTotal
if $from == $upto 0 6916 6916
293  
294 6916 my $ceil = 2147483647;
295  
296 6916 ▶ $from = 0 if !$from || $from > $ceil;
Branch: 1 branch
BranchTrueFalseTotal
if not $from or $from > $ceil 4917 1999 6916
Condition66%2/3
not $from or $from > $ceil
l!l&&r!l&&!r
491701999
MC/DC50%1/2
not $from or $from > $ceil
not $from $from > $ceil
Truth table66%2/3
not(A) or B
A= not $fromB= $from > $ceil
ABresult
1X1
011
000
297 6916 ▶ $upto = $ceil if !$upto || $upto > $ceil;
Branch: 1 branch
BranchTrueFalseTotal
if not $upto or $upto > $ceil 0 6916 6916
Condition33%1/3
not $upto or $upto > $ceil
l!l&&r!l&&!r
006916
MC/DC0%0/2
not $upto or $upto > $ceil
not $upto $upto > $ceil
Truth table33%1/3
not(A) or B
A= not $uptoB= $upto > $ceil
ABresult
1X1
011
000
298  
299 6916 return $from + int($self->pick(($upto-$from) + 1));
300 }
301  
302 897 ▶sub repeat {
Subroutine repeat: called CC=5 SCAR=16.1
Pod documented
303 897 my ($self, $times, $code, @args) = @_;
304  
305 897 my @values;
306  
307 897 ▶ $code ||= 'digit';
Condition100%2/2
$code ||= "digit"
l!l
769128
MC/DC100%1/1
$code ||= "digit"
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
308 897 ▶ $times ||= 1;
Condition100%2/2
$times ||= 1
l!l
84651
MC/DC100%1/1
$times ||= 1
$times
Truth table100%2/2
A
A= $times
Aresult
11
00
309  
310 897 push @values, $self->$code(@args) for 1..$times;
311  
312 897 ▶ return wantarray ? (@values) : join('', @values);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 128 769 897
313 }
314  
315 130 ▶sub reseed {
Subroutine reseed: called CC=3 SCAR=11.0
Pod documented
316 130 my ($self, $seed) = @_;
317  
318 130 ▶ my $THIS_SEED = !$seed || $seed =~ /\D/ ? $SELF_SEED : $seed;
Branch: 1 branch
BranchTrueFalseTotal
!$seed || $seed =~ /\D/u ? : 1 129 130
Condition66%2/3
not $seed or $seed =~ /\D/u
l!l&&r!l&&!r
10129
MC/DC50%1/2
not $seed or $seed =~ /\D/u
not $seed $seed =~ /\D/u
Truth table66%2/3
not(A) or B
A= not $seedB= $seed =~ /\D/u
ABresult
1X1
011
000
319  
320 130 $self->value($THIS_SEED);
321  
322 130 srand $THIS_SEED;
323  
324 130 return $self;
325 }
326  
327 1 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
328 1 my ($self) = @_;
329  
330 1 $self->reseed($SELF_SEED);
331  
332 1 srand $SELF_SEED;
333  
334 1 return $self;
335 }
336  
337 1 ▶sub restore {
Subroutine restore: called CC=1 SCAR=0.0
Pod documented
338 1 my ($self) = @_;
339  
340 1 $self->reseed($ORIG_SEED);
341  
342 1 srand $ORIG_SEED;
343  
344 1 return $self;
345 }
346  
347 4815 ▶sub select {
Subroutine select: called CC=5 SCAR=16.6
Pod documented
348 4815 my ($self, $data) = @_;
349  
350 4815 ▶ if (UNIVERSAL::isa($data, 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($data, "ARRAY")) 4764 51 4815
351 4764 my $keys = @$data;
352 4764 ▶ my $rand = $self->range(0, $keys <= 0 ? 0 : $keys - 1);
Branch: 1 branch
BranchTrueFalseTotal
$keys <= 0 ? : 0 4764 4764
353 4764 return (@$data)[$rand];
354 }
355  
356 51 ▶ if (UNIVERSAL::isa($data, 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($data, "HASH")) 51 0 51
357 51 my $keys = keys(%$data);
358 51 ▶ my $rand = $self->range(0, $keys <= 0 ? 0 : $keys - 1);
Branch: 1 branch
BranchTrueFalseTotal
$keys <= 0 ? : 0 51 51
359 51 return $$data{(sort keys %$data)[$rand]};
360 }
361  
362 0 return undef;
363 }
364  
365 57 ▶sub shuffle {
Subroutine shuffle: called CC=3 SCAR=11.0
Pod documented
366 57 my ($self, $data) = @_;
367  
368 57 ▶ my @characters = split '', $data || '';
Condition50%1/2
$data || ''
l!l
570
MC/DC0%0/1
$data || ''
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
369  
370 57 ▶ for (my $i = @characters - 1; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 789 57 846
371 789 my $j = $self->pick($i + 1); @characters[$i, $j] = @characters[$j, $i];
372 }
373  
374 57 return join '', @characters;
375 }
376  
377 697 ▶sub symbol {
Subroutine symbol: called CC=1 SCAR=0.0
Pod documented
378 697 my ($self) = @_;
379  
380 697 state $symbols = [split '', q(~!@#$%^&*\(\)-_=+[]{}\|;:'",./<>?)];
381  
382 697 return $self->select($symbols);
383 }
384  
385 102 ▶sub symbols {
Subroutine symbols: called CC=2 SCAR=7.1
Pod documented
386 102 my ($self, $times) = @_;
387  
388 102 ▶ my $result = $self->collect($times || 1, 'symbol');
Condition50%1/2
$times || 1
l!l
1020
MC/DC0%0/1
$times || 1
$times
Truth table50%1/2
A
A= $times
Aresult
11
00
389  
390 102 return $result;
391 }
392  
393 105 ▶sub token {
Subroutine token: called CC=1 SCAR=0.0
Pod documented
394 105 my ($self) = @_;
395  
396 105 require Sys::Hostname;
397  
398 105 state $hostname = Sys::Hostname::hostname();
399  
400 105 state $instance = 1;
401  
402 105 require Time::HiRes;
403  
404 105 my ($seconds, $microseconds) = Time::HiRes::gettimeofday();
405  
406 105 require Digest::MD5;
407  
408 105 my $result = Digest::MD5::md5_hex(join ':', $hostname, $^T, $^O, $^X, $0, $$, $seconds, $microseconds, $instance++);
409  
410 105 return $result;
411 }
412  
413 735 ▶sub uppercased {
Subroutine uppercased: called CC=1 SCAR=0.0
Pod documented
414 735 my ($self) = @_;
415  
416 735 return uc(chr($self->range(97, 122)));
417 }
418  
419 21 ▶sub urlsafe {
Subroutine urlsafe: called CC=1 SCAR=0.0
Pod documented
420 21 my ($self) = @_;
421  
422 21 my $result = $self->base64;
423  
424 21 $result =~ tr{+/}{-_}; $result =~ s/=+$//;
425  
426 21 return $result;
427 }
428  
429 21 ▶sub uuid {
Subroutine uuid: called CC=1 SCAR=0.0
Pod documented
430 21 my ($self) = @_;
431  
432 21 my $result = $self->token;
433  
434 21 $result =~ s/^(.{8})(.{4})(.{4})(.{4})(.{12})$/$1-$2-$3-$4-$5/;
435  
436 21 return $result;
437 }
438  
439 2 1;
440  
441  
442  
443 =head1 NAME
444  
445 Venus::Random - Random Class
446  
447 =cut
448  
449 =head1 ABSTRACT
450  
451 Random Class for Perl 5
452  
453 =cut
454  
455 =head1 SYNOPSIS
456  
457 package main;
458  
459 use Venus::Random;
460  
461 my $random = Venus::Random->new(42);
462  
463 # my $bit = $random->bit;
464  
465 # 1
466  
467 =cut
468  
469 =head1 DESCRIPTION
470  
471 This package provides an object-oriented interface for Perl's pseudo-random
472 number generator (or PRNG) which produces a deterministic sequence of bits
473 which approximate true randomness.
474  
475 =cut
476  
477 =head1 INHERITS
478  
479 This package inherits behaviors from:
480  
481 L<Venus::Kind::Utility>
482  
483 =cut
484  
485 =head1 INTEGRATES
486  
487 This package integrates behaviors from:
488  
489 L<Venus::Role::Accessible>
490  
491 L<Venus::Role::Buildable>
492  
493 L<Venus::Role::Valuable>
494  
495 =cut
496  
497 =head1 METHODS
498  
499 This package provides the following methods:
500  
501 =cut
502  
503 =head2 alphanumeric
504  
505 alphanumeric() (string)
506  
507 The alphanumeric method returns a random alphanumeric character, which is
508 either a L</digit>, or L</letter> value.
509  
510 I<Since C<4.15>>
511  
512 =over 4
513  
514 =item alphanumeric example 1
515  
516 # given: synopsis
517  
518 package main;
519  
520 my $alphanumeric = $random->alphanumeric;
521  
522 # "C"
523  
524 # $alphanumeric = $random->alphanumeric;
525  
526 # 0
527  
528 =back
529  
530 =cut
531  
532 =head2 alphanumerics
533  
534 alphanumerics(number $count) (string)
535  
536 The alphanumerics method returns C<n> L</alphanumeric> characters based on the
537 number (i.e. count) provided.
538  
539 I<Since C<4.15>>
540  
541 =over 4
542  
543 =item alphanumerics example 1
544  
545 # given: synopsis
546  
547 package main;
548  
549 my $alphanumerics = $random->alphanumerics(5);
550  
551 # "C0Mma"
552  
553 # $alphanumerics = $random->alphanumerics(5);
554  
555 # "x5498"
556  
557 =back
558  
559 =cut
560  
561 =head2 base64
562  
563 base64() (string)
564  
565 The base64 method returns a unique randomly generated base64 encoded string.
566  
567 I<Since C<4.15>>
568  
569 =over 4
570  
571 =item base64 example 1
572  
573 # given: synopsis
574  
575 package main;
576  
577 my $base64 = $random->base64;
578  
579 # "gApCFiIVBS7JHxtVDkvQmOe2CU2RsVgzauI5EMMYI9s="
580  
581 # $base64 = $random->base64;
582  
583 # "ZdxOdj268Ge18X97cKr5yH6EJqfEdbI1OeeWJVH/XFQ="
584  
585 =back
586  
587 =cut
588  
589 =head2 bit
590  
591 bit() (number)
592  
593 The bit method returns a C<1> or C<0> value, randomly.
594  
595 I<Since C<1.11>>
596  
597 =over 4
598  
599 =item bit example 1
600  
601 # given: synopsis
602  
603 package main;
604  
605 my $bit = $random->bit;
606  
607 # 0
608  
609 # $bit = $random->bit;
610  
611 # 1
612  
613 =back
614  
615 =cut
616  
617 =head2 bits
618  
619 bits(number $count) (string)
620  
621 The bits method returns C<n> L</bit> characters based on the number (i.e.
622 count) provided.
623  
624 I<Since C<4.15>>
625  
626 =over 4
627  
628 =item bits example 1
629  
630 # given: synopsis
631  
632 package main;
633  
634 my $bits = $random->bits(5);
635  
636 # "01111"
637  
638 # $bits = $random->bits(5);
639  
640 # "01100"
641  
642 =back
643  
644 =cut
645  
646 =head2 boolean
647  
648 boolean() (boolean)
649  
650 The boolean method returns a C<true> or C<false> value, randomly.
651  
652 I<Since C<1.11>>
653  
654 =over 4
655  
656 =item boolean example 1
657  
658 # given: synopsis
659  
660 package main;
661  
662 my $boolean = $random->boolean;
663  
664 # 0
665  
666 # $boolean = $random->boolean;
667  
668 # 1
669  
670 =back
671  
672 =cut
673  
674 =head2 byte
675  
676 byte() (string)
677  
678 The byte method returns random byte characters, randomly.
679  
680 I<Since C<1.11>>
681  
682 =over 4
683  
684 =item byte example 1
685  
686 # given: synopsis
687  
688 package main;
689  
690 my $byte = $random->byte;
691  
692 # "\xBE"
693  
694 # $byte = $random->byte;
695  
696 # "W"
697  
698 =back
699  
700 =cut
701  
702 =head2 bytes
703  
704 bytes(number $count) (string)
705  
706 The bytes method returns C<n> L</byte> characters based on the number (i.e.
707 count) provided.
708  
709 I<Since C<4.15>>
710  
711 =over 4
712  
713 =item bytes example 1
714  
715 # given: synopsis
716  
717 package main;
718  
719 my $bytes = $random->bytes(5);
720  
721 # "\xBE\x57\x1C\x6C\x14"
722  
723 # $bytes = $random->bytes(5);
724  
725 # "\xDB\x7F\x7A\xB0\xD5"
726  
727 =back
728  
729 =cut
730  
731 =head2 character
732  
733 character() (string)
734  
735 The character method returns a random character, which is either a L</digit>,
736 L</letter>, or L</symbol> value.
737  
738 I<Since C<1.11>>
739  
740 =over 4
741  
742 =item character example 1
743  
744 # given: synopsis
745  
746 package main;
747  
748 my $character = $random->character;
749  
750 # ")"
751  
752 # $character = $random->character;
753  
754 # 4
755  
756 =back
757  
758 =cut
759  
760 =head2 characters
761  
762 characters(number $count) (string)
763  
764 The characters method returns C<n> L</character> characters based on the number
765 (i.e. count) provided.
766  
767 I<Since C<4.15>>
768  
769 =over 4
770  
771 =item characters example 1
772  
773 # given: synopsis
774  
775 package main;
776  
777 my $characters = $random->characters(5);
778  
779 # ")48R+"
780  
781 # $characters = $random->characters(5);
782  
783 # "a}[Lb"
784  
785 =back
786  
787 =cut
788  
789 =head2 collect
790  
791 collect(number $times, string | coderef $code, any @args) (number | string)
792  
793 The collect method dispatches to the specified method or coderef, repeatedly
794 based on the number of C<$times> specified, and returns the random concatenated
795 results from each dispatched call. By default, if no arguments are provided,
796 this method dispatches to L</digit>.
797  
798 I<Since C<1.11>>
799  
800 =over 4
801  
802 =item collect example 1
803  
804 # given: synopsis
805  
806 package main;
807  
808 my $collect = $random->collect;
809  
810 # 7
811  
812 # $collect = $random->collect;
813  
814 # 3
815  
816 =back
817  
818 =over 4
819  
820 =item collect example 2
821  
822 # given: synopsis
823  
824 package main;
825  
826 my $collect = $random->collect(2);
827  
828 # 73
829  
830 # $collect = $random->collect(2);
831  
832 # 14
833  
834 =back
835  
836 =over 4
837  
838 =item collect example 3
839  
840 # given: synopsis
841  
842 package main;
843  
844 my $collect = $random->collect(5, "letter");
845  
846 # "iKWMv"
847  
848 # $collect = $random->collect(5, "letter");
849  
850 # "Papmm"
851  
852  
853  
854  
855 =back
856  
857 =over 4
858  
859 =item collect example 4
860  
861 # given: synopsis
862  
863 package main;
864  
865 my $collect = $random->collect(10, "character");
866  
867 # ")48R+a}[Lb"
868  
869 # $collect = $random->collect(10, "character");
870  
871 # "?&0725^,0w"
872  
873 =back
874  
875 =cut
876  
877 =head2 digest
878  
879 digest() (string)
880  
881 The digest method returns a unique randomly generated L<"md5"|Digest::MD5>
882 digest.
883  
884 I<Since C<4.15>>
885  
886 =over 4
887  
888 =item digest example 1
889  
890 # given: synopsis
891  
892 package main;
893  
894 my $digest = $random->digest;
895  
896 # "86eb5865c3e4a1457fbefcc93e037459"
897  
898 # $digest = $random->digest;
899  
900 # "9be02d56ece7efe68bc59d2ebf3c4ed7"
901  
902 =back
903  
904 =cut
905  
906 =head2 digit
907  
908 digit() (number)
909  
910 The digit method returns a random digit between C<0> and C<9>.
911  
912 I<Since C<1.11>>
913  
914 =over 4
915  
916 =item digit example 1
917  
918 # given: synopsis
919  
920 package main;
921  
922 my $digit = $random->digit;
923  
924 # 7
925  
926 # $digit = $random->digit;
927  
928 # 3
929  
930 =back
931  
932 =cut
933  
934 =head2 digits
935  
936 digits(number $count) (string)
937  
938 The digits method returns C<n> L</digit> characters based on the number (i.e.
939 count) provided.
940  
941 I<Since C<4.15>>
942  
943 =over 4
944  
945 =item digits example 1
946  
947 # given: synopsis
948  
949 package main;
950  
951 my $digits = $random->digits(5);
952  
953 # 73140
954  
955 # $digits = $random->digits(5);
956  
957 # 84468
958  
959 =back
960  
961 =cut
962  
963 =head2 float
964  
965 float(number $place, number $from, number $upto) (number)
966  
967 The float method returns a random float.
968  
969 I<Since C<1.11>>
970  
971 =over 4
972  
973 =item float example 1
974  
975 # given: synopsis
976  
977 package main;
978  
979 my $float = $random->float;
980  
981 # 1447361.5
982  
983 # $float = $random->float;
984  
985 # "0.0000"
986  
987 =back
988  
989 =over 4
990  
991 =item float example 2
992  
993 # given: synopsis
994  
995 package main;
996  
997 my $float = $random->float(2);
998  
999 # 380690.82
1000  
1001 # $float = $random->float(2);
1002  
1003 # 694.57
1004  
1005 =back
1006  
1007 =over 4
1008  
1009 =item float example 3
1010  
1011 # given: synopsis
1012  
1013 package main;
1014  
1015 my $float = $random->float(2, 1, 5);
1016  
1017 # 3.98
1018  
1019 # $float = $random->float(2, 1, 5);
1020  
1021 # 2.37
1022  
1023 =back
1024  
1025 =over 4
1026  
1027 =item float example 4
1028  
1029 # given: synopsis
1030  
1031 package main;
1032  
1033 my $float = $random->float(3, 1, 2);
1034  
1035 # 1.745
1036  
1037 # $float = $random->float(3, 1, 2);
1038  
1039 # 1.343
1040  
1041 =back
1042  
1043 =cut
1044  
1045 =head2 hexdecimal
1046  
1047 hexdecimal() (string)
1048  
1049 The hexdecimal method returns a hexdecimal character.
1050  
1051 I<Since C<4.15>>
1052  
1053 =over 4
1054  
1055 =item hexdecimal example 1
1056  
1057 # given: synopsis
1058  
1059 package main;
1060  
1061 my $hexdecimal = $random->hexdecimal;
1062  
1063 # "b"
1064  
1065 # $hexdecimal = $random->hexdecimal;
1066  
1067 # 5
1068  
1069 =back
1070  
1071 =cut
1072  
1073 =head2 hexdecimals
1074  
1075 hexdecimals(number $count) (string)
1076  
1077 The hexdecimals method returns C<n> L</hexdecimal> characters based on the
1078 number (i.e. count) provided.
1079  
1080 I<Since C<4.15>>
1081  
1082 =over 4
1083  
1084 =item hexdecimals example 1
1085  
1086 # given: synopsis
1087  
1088 package main;
1089  
1090 my $hexdecimals = $random->hexdecimals(5);
1091  
1092 # "b5161"
1093  
1094 # $hexdecimals = $random->hexdecimals(5);
1095  
1096 # "d77bd"
1097  
1098 =back
1099  
1100 =cut
1101  
1102 =head2 id
1103  
1104 id() (number)
1105  
1106 The id method returns a machine unique thread-safe random numerical identifier.
1107  
1108 I<Since C<4.15>>
1109  
1110 =over 4
1111  
1112 =item id example 1
1113  
1114 # given: synopsis
1115  
1116 package main;
1117  
1118 my $id = $random->id;
1119  
1120 # 1729257495154941
1121  
1122 =back
1123  
1124 =cut
1125  
1126 =head2 letter
1127  
1128 letter() (string)
1129  
1130 The letter method returns a random letter, which is either an L</uppercased> or
1131 L</lowercased> value.
1132  
1133 I<Since C<1.11>>
1134  
1135 =over 4
1136  
1137 =item letter example 1
1138  
1139 # given: synopsis
1140  
1141 package main;
1142  
1143 my $letter = $random->letter;
1144  
1145 # "i"
1146  
1147 # $letter = $random->letter;
1148  
1149 # "K"
1150  
1151 =back
1152  
1153 =cut
1154  
1155 =head2 letters
1156  
1157 letters(number $count) (string)
1158  
1159 The letters method returns C<n> L</letter> characters based on the number (i.e.
1160 count) provided.
1161  
1162 I<Since C<4.15>>
1163  
1164 =over 4
1165  
1166 =item letters example 1
1167  
1168 # given: synopsis
1169  
1170 package main;
1171  
1172 my $letters = $random->letters(5);
1173  
1174 # "iKWMv"
1175  
1176 # $letters = $random->letters(5);
1177  
1178 # "Papmm"
1179  
1180 =back
1181  
1182 =cut
1183  
1184 =head2 lowercased
1185  
1186 lowercased() (string)
1187  
1188 The lowercased method returns a random lowercased letter.
1189  
1190 I<Since C<1.11>>
1191  
1192 =over 4
1193  
1194 =item lowercased example 1
1195  
1196 # given: synopsis
1197  
1198 package main;
1199  
1200 my $lowercased = $random->lowercased;
1201  
1202 # "t"
1203  
1204 # $lowercased = $random->lowercased;
1205  
1206 # "i"
1207  
1208 =back
1209  
1210 =cut
1211  
1212 =head2 new
1213  
1214 new(any @args) (Venus::Random)
1215  
1216 The new method constructs an instance of the package.
1217  
1218 I<Since C<4.15>>
1219  
1220 =over 4
1221  
1222 =item new example 1
1223  
1224 package main;
1225  
1226 use Venus::Random;
1227  
1228 my $new = Venus::Random->new;
1229  
1230 # bless(..., "Venus::Random")
1231  
1232 =back
1233  
1234 =over 4
1235  
1236 =item new example 2
1237  
1238 package main;
1239  
1240 use Venus::Random;
1241  
1242 my $new = Venus::Random->new(42);
1243  
1244 # bless(..., "Venus::Random")
1245  
1246 =back
1247  
1248 =over 4
1249  
1250 =item new example 3
1251  
1252 package main;
1253  
1254 use Venus::Random;
1255  
1256 my $new = Venus::Random->new(value => 42);
1257  
1258 # bless(..., "Venus::Random")
1259  
1260 =back
1261  
1262 =cut
1263  
1264 =head2 nonce
1265  
1266 nonce() (string)
1267  
1268 The nonce method returns a 10-character L</alphanumeric> string.
1269  
1270 I<Since C<4.15>>
1271  
1272 =over 4
1273  
1274 =item nonce example 1
1275  
1276 # given: synopsis
1277  
1278 package main;
1279  
1280 my $nonce = $random->nonce;
1281  
1282 # "j2q1G45903"
1283  
1284 # $nonce = $random->nonce;
1285  
1286 # "7nmi8mT5Io"
1287  
1288 =back
1289  
1290 =cut
1291  
1292 =head2 nonzero
1293  
1294 nonzero(string | coderef $code, any @args) (number | string)
1295  
1296 The nonzero method dispatches to the specified method or coderef and returns
1297 the random value ensuring that it's never zero, not even a percentage of zero.
1298 By default, if no arguments are provided, this method dispatches to L</digit>.
1299  
1300 I<Since C<1.11>>
1301  
1302 =over 4
1303  
1304 =item nonzero example 1
1305  
1306 # given: synopsis
1307  
1308 package main;
1309  
1310 my $nonzero = $random->nonzero;
1311  
1312 # 7
1313  
1314 # $nonzero = $random->nonzero;
1315  
1316 # 3
1317  
1318 =back
1319  
1320 =over 4
1321  
1322 =item nonzero example 2
1323  
1324 # given: synopsis
1325  
1326 package main;
1327  
1328 my $nonzero = $random->nonzero("pick");
1329  
1330 # 1.74452500006101
1331  
1332 # $nonzero = $random->nonzero("pick");
1333  
1334 # 1.34270147871891
1335  
1336 =back
1337  
1338 =over 4
1339  
1340 =item nonzero example 3
1341  
1342 # given: synopsis
1343  
1344 package main;
1345  
1346 my $nonzero = $random->nonzero("number");
1347  
1348 # 3427014
1349  
1350 # $nonzero = $random->nonzero("number");
1351  
1352 # 3
1353  
1354 =back
1355  
1356 =over 4
1357  
1358 =item nonzero example 4
1359  
1360 # given: synopsis
1361  
1362 package main;
1363  
1364 my $nonzero = $random->nonzero("number", 0, 10);
1365  
1366 # 8
1367  
1368 # $nonzero = $random->nonzero("number", 0, 10);
1369  
1370 # 3
1371  
1372 =back
1373  
1374 =cut
1375  
1376 =head2 number
1377  
1378 number(number $from, number $upto) (number)
1379  
1380 The number method returns a random number within the range provided. If no
1381 arguments are provided, the range is from C<0> to C<2147483647>. If only the
1382 first argument is provided, it's treated as the desired length of the number.
1383  
1384 I<Since C<1.11>>
1385  
1386 =over 4
1387  
1388 =item number example 1
1389  
1390 # given: synopsis
1391  
1392 package main;
1393  
1394 my $number = $random->number;
1395  
1396 # 3427014
1397  
1398 # $number = $random->number;
1399  
1400 # 3
1401  
1402 =back
1403  
1404 =over 4
1405  
1406 =item number example 2
1407  
1408 # given: synopsis
1409  
1410 package main;
1411  
1412 my $number = $random->number(5, 50);
1413  
1414 # 39
1415  
1416 # $number = $random->number(5, 50);
1417  
1418 # 20
1419  
1420 =back
1421  
1422 =over 4
1423  
1424 =item number example 3
1425  
1426 # given: synopsis
1427  
1428 package main;
1429  
1430 my $number = $random->number(100, 20);
1431  
1432 # 42
1433  
1434 # $number = $random->number(100, 20);
1435  
1436 # 73
1437  
1438 =back
1439  
1440 =over 4
1441  
1442 =item number example 4
1443  
1444 # given: synopsis
1445  
1446 package main;
1447  
1448 my $number = $random->number(5);
1449  
1450 # 74451
1451  
1452 # $number = $random->number(5);
1453  
1454 # 34269
1455  
1456 =back
1457  
1458 =cut
1459  
1460 =head2 numbers
1461  
1462 numbers(number $count) (string)
1463  
1464 The numbers method returns C<n> L</number> characters (between C<1> and C<9>)
1465 based on the number (i.e. count) provided.
1466  
1467 I<Since C<4.15>>
1468  
1469 =over 4
1470  
1471 =item numbers example 1
1472  
1473 # given: synopsis
1474  
1475 package main;
1476  
1477 my $numbers = $random->numbers(5);
1478  
1479 # 74141
1480  
1481 # $numbers = $random->numbers(5);
1482  
1483 # 85578
1484  
1485 =back
1486  
1487 =cut
1488  
1489 =head2 password
1490  
1491 password(number $count) (string)
1492  
1493 The password method returns C<n> L<"characters"|/character> based on the number
1494 (i.e. count) provided. The default length is 16.
1495  
1496 I<Since C<4.15>>
1497  
1498 =over 4
1499  
1500 =item password example 1
1501  
1502 # given: synopsis
1503  
1504 package main;
1505  
1506 my $password = $random->password;
1507  
1508 # "0*89{745axCMg0m2"
1509  
1510 # $password = $random->password;
1511  
1512 # "5rV22V24>6Q1v#6N"
1513  
1514 =back
1515  
1516 =cut
1517  
1518 =head2 pick
1519  
1520 pick(Num $data) (Num)
1521  
1522 The pick method is the random number generator and returns a random number. By
1523 default, calling this method is equivalent to call L<perlfunc/rand>. This
1524 method can be overridden in a subclass to provide a custom generator, e.g. a
1525 more cyptographically secure generator.
1526  
1527 I<Since C<1.23>>
1528  
1529 =over 4
1530  
1531 =item pick example 1
1532  
1533 # given: synopsis
1534  
1535 package main;
1536  
1537 my $pick = $random->pick;
1538  
1539 # 0.744525000061007
1540  
1541 # $pick = $random->pick;
1542  
1543 # 0.342701478718908
1544  
1545 =back
1546  
1547 =over 4
1548  
1549 =item pick example 2
1550  
1551 # given: synopsis
1552  
1553 package main;
1554  
1555 my $pick = $random->pick(100);
1556  
1557 # 74.4525000061007
1558  
1559 # $pick = $random->pick(100);
1560  
1561 # 34.2701478718908
1562  
1563 =back
1564  
1565 =over 4
1566  
1567 =item pick example 3
1568  
1569 # given: synopsis
1570  
1571 package main;
1572  
1573 my $pick = $random->pick(2);
1574  
1575 # 1.48905000012201
1576  
1577 # $pick = $random->pick(2);
1578  
1579 # 0.685402957437816
1580  
1581 =back
1582  
1583 =cut
1584  
1585 =head2 range
1586  
1587 range(string $from, string $to) (number)
1588  
1589 The range method returns a random number within the range provided. If no
1590 arguments are provided, the range is from C<0> to C<2147483647>.
1591  
1592 I<Since C<1.11>>
1593  
1594 =over 4
1595  
1596 =item range example 1
1597  
1598 # given: synopsis
1599  
1600 package main;
1601  
1602 my $range = $random->range(1, 10);
1603  
1604 # 8
1605  
1606 # $range = $random->range(1, 10);
1607  
1608 # 4
1609  
1610 =back
1611  
1612 =over 4
1613  
1614 =item range example 2
1615  
1616 # given: synopsis
1617  
1618 package main;
1619  
1620 my $range = $random->range(10, 1);
1621  
1622 # 5
1623  
1624 # $range = $random->range(10, 1);
1625  
1626 # 8
1627  
1628 =back
1629  
1630 =over 4
1631  
1632 =item range example 3
1633  
1634 # given: synopsis
1635  
1636 package main;
1637  
1638 my $range = $random->range(0, 60);
1639  
1640 # 45
1641  
1642 # $range = $random->range(0, 60);
1643  
1644 # 20
1645  
1646 =back
1647  
1648 =over 4
1649  
1650 =item range example 4
1651  
1652 # given: synopsis
1653  
1654 package main;
1655  
1656 my $range = $random->range(-5, -1);
1657  
1658 # -2
1659  
1660 # $range = $random->range(-5, -1);
1661  
1662 # -4
1663  
1664 =back
1665  
1666 =cut
1667  
1668 =head2 repeat
1669  
1670 repeat(number $times, string | coderef $code, any @args) (number | string)
1671  
1672 The repeat method dispatches to the specified method or coderef, repeatedly
1673 based on the number of C<$times> specified, and returns the random results from
1674 each dispatched call. In list context, the results from each call is returned
1675 as a list, in scalar context the results are concatenated.
1676  
1677 I<Since C<1.11>>
1678  
1679 =over 4
1680  
1681 =item repeat example 1
1682  
1683 # given: synopsis
1684  
1685 package main;
1686  
1687 my @repeat = $random->repeat(2);
1688  
1689 # (7, 3)
1690  
1691 # @repeat = $random->repeat(2);
1692  
1693 # (1, 4)
1694  
1695  
1696  
1697  
1698 =back
1699  
1700 =over 4
1701  
1702 =item repeat example 2
1703  
1704 # given: synopsis
1705  
1706 package main;
1707  
1708 my @repeat = $random->repeat(2, "float");
1709  
1710 # (1447361.5, "0.0000")
1711  
1712 # @repeat = $random->repeat(2, "float");
1713  
1714 # ("482092.1040", 1555.7410393)
1715  
1716  
1717  
1718  
1719 =back
1720  
1721 =over 4
1722  
1723 =item repeat example 3
1724  
1725 # given: synopsis
1726  
1727 package main;
1728  
1729 my @repeat = $random->repeat(2, "character");
1730  
1731 # (")", 4)
1732  
1733 # @repeat = $random->repeat(2, "character");
1734  
1735 # (8, "R")
1736  
1737 =back
1738  
1739 =cut
1740  
1741 =head2 reseed
1742  
1743 reseed(string $seed) (Venus::Random)
1744  
1745 The reseed method sets the L<perlfunc/srand> (i.e. the PRNG seed) to the value
1746 provided, or the default value used on instanstiation when no seed is passed to
1747 the constructor. This method returns the object that invoked it.
1748  
1749 I<Since C<1.11>>
1750  
1751 =over 4
1752  
1753 =item reseed example 1
1754  
1755 # given: synopsis
1756  
1757 package main;
1758  
1759 my $reseed = $random->reseed;
1760  
1761 # bless({value => ...}, "Venus::Random")
1762  
1763 # my $bit = $random->bit;
1764  
1765 # 0
1766  
1767 =back
1768  
1769 =over 4
1770  
1771 =item reseed example 2
1772  
1773 # given: synopsis
1774  
1775 package main;
1776  
1777 my $reseed = $random->reseed(42);
1778  
1779 # bless({value => 42}, "Venus::Random")
1780  
1781 # my $bit = $random->bit;
1782  
1783 # 0
1784  
1785 =back
1786  
1787 =cut
1788  
1789 =head2 reset
1790  
1791 reset() (Venus::Random)
1792  
1793 The reset method sets the L<perlfunc/srand> (i.e. the PRNG seed) to the default
1794 value used on instanstiation when no seed is passed to the constructor. This
1795 method returns the object that invoked it.
1796  
1797 I<Since C<1.11>>
1798  
1799 =over 4
1800  
1801 =item reset example 1
1802  
1803 # given: synopsis
1804  
1805 package main;
1806  
1807 my $reset = $random->reset;
1808  
1809 # bless({value => ...}, "Venus::Random")
1810  
1811 =back
1812  
1813 =cut
1814  
1815 =head2 restore
1816  
1817 restore() (Venus::Random)
1818  
1819 The restore method sets the L<perlfunc/srand> (i.e. the PRNG seed) to the
1820 original value used by L<perlfunc/rand>. This method returns the object that
1821 invoked it.
1822  
1823 I<Since C<1.11>>
1824  
1825 =over 4
1826  
1827 =item restore example 1
1828  
1829 # given: synopsis
1830  
1831 package main;
1832  
1833 my $restore = $random->restore;
1834  
1835 # bless({value => ...}, "Venus::Random")
1836  
1837 =back
1838  
1839 =cut
1840  
1841 =head2 select
1842  
1843 select(arrayref | hashref $data) (any)
1844  
1845 The select method returns a random value from the I<"hashref"> or I<"arrayref">
1846 provided.
1847  
1848 I<Since C<1.11>>
1849  
1850 =over 4
1851  
1852 =item select example 1
1853  
1854 # given: synopsis
1855  
1856 package main;
1857  
1858 my $select = $random->select(["a".."d"]);
1859  
1860 # "c"
1861  
1862 # $select = $random->select(["a".."d"]);
1863  
1864 # "b"
1865  
1866 =back
1867  
1868 =over 4
1869  
1870 =item select example 2
1871  
1872 # given: synopsis
1873  
1874 package main;
1875  
1876 my $select = $random->select({"a".."h"});
1877  
1878 # "f"
1879  
1880 # $select = $random->select({"a".."h"});
1881  
1882 # "d"
1883  
1884 =back
1885  
1886 =cut
1887  
1888 =head2 shuffle
1889  
1890 shuffle(string $string) (string)
1891  
1892 The shuffle method returns the string provided with its characters randomly
1893 rearranged.
1894  
1895 I<Since C<4.15>>
1896  
1897 =over 4
1898  
1899 =item shuffle example 1
1900  
1901 # given: synopsis
1902  
1903 package main;
1904  
1905 my $shuffle = $random->shuffle('hello');
1906  
1907 # "olhel"
1908  
1909 # $shuffle = $random->shuffle('hello');
1910  
1911 # "loelh"
1912  
1913 =back
1914  
1915 =cut
1916  
1917 =head2 symbol
1918  
1919 symbol() (string)
1920  
1921 The symbol method returns a random symbol.
1922  
1923 I<Since C<1.11>>
1924  
1925 =over 4
1926  
1927 =item symbol example 1
1928  
1929 # given: synopsis
1930  
1931 package main;
1932  
1933 my $symbol = $random->symbol;
1934  
1935 # "'"
1936  
1937 # $symbol = $random->symbol;
1938  
1939 # ")"
1940  
1941 =back
1942  
1943 =cut
1944  
1945 =head2 symbols
1946  
1947 symbols(number $count) (string)
1948  
1949 The symbols method returns C<n> L</symbol> characters based on the number (i.e.
1950 count) provided.
1951  
1952 I<Since C<4.15>>
1953  
1954 =over 4
1955  
1956 =item symbols example 1
1957  
1958 # given: synopsis
1959  
1960 package main;
1961  
1962 my $symbols = $random->symbols(5);
1963  
1964 # "')#=@"
1965  
1966 # $symbols = $random->symbols(5);
1967  
1968 # ".[+;,"
1969  
1970 =back
1971  
1972 =cut
1973  
1974 =head2 token
1975  
1976 token() (string)
1977  
1978 The token method returns a unique randomly generated L<"md5"|Digest::MD5>
1979 digest.
1980  
1981 I<Since C<4.15>>
1982  
1983 =over 4
1984  
1985 =item token example 1
1986  
1987 # given: synopsis
1988  
1989 package main;
1990  
1991 my $token = $random->token;
1992  
1993 # "86eb5865c3e4a1457fbefcc93e037459"
1994  
1995 # $token = $random->token;
1996  
1997 # "9be02d56ece7efe68bc59d2ebf3c4ed7"
1998  
1999 =back
2000  
2001 =cut
2002  
2003 =head2 uppercased
2004  
2005 uppercased() (string)
2006  
2007 The uppercased method returns a random uppercased letter.
2008  
2009 I<Since C<1.11>>
2010  
2011 =over 4
2012  
2013 =item uppercased example 1
2014  
2015 # given: synopsis
2016  
2017 package main;
2018  
2019 my $uppercased = $random->uppercased;
2020  
2021 # "T"
2022  
2023 # $uppercased = $random->uppercased;
2024  
2025 # "I"
2026  
2027 =back
2028  
2029 =cut
2030  
2031 =head2 urlsafe
2032  
2033 urlsafe() (string)
2034  
2035 The urlsafe method returns a unique randomly generated URL-safe string based on
2036 L</base64>.
2037  
2038 I<Since C<4.15>>
2039  
2040 =over 4
2041  
2042 =item urlsafe example 1
2043  
2044 # given: synopsis
2045  
2046 package main;
2047  
2048 my $urlsafe = $random->urlsafe;
2049  
2050 # "WtdsCPBQDKXPv2tcuFbBFcdDtJ6EZRyE3Xke0e65YRQ"
2051  
2052 # $urlsafe = $random->urlsafe;
2053  
2054 # "xXq7Mkwo7nLsFjMW8mvKgdzac5m4X0gFMykO1r0d7GA"
2055  
2056 =back
2057  
2058 =cut
2059  
2060 =head2 uuid
2061  
2062 uuid() (string)
2063  
2064 The uuid method returns a machine-unique randomly generated psuedo UUID string.
2065 B<Note:> The identifier returned attempts to be unique across network devices
2066 but its uniqueness can't be guaranteed.
2067  
2068 I<Since C<4.15>>
2069  
2070 =over 4
2071  
2072 =item uuid example 1
2073  
2074 # given: synopsis
2075  
2076 package main;
2077  
2078 my $uuid = $random->uuid;
2079  
2080 # "0d3eea5f-1826-3d37-e242-72ea44a157fd"
2081  
2082 # $uuid = $random->uuid;
2083  
2084 # "6e179032-c7fe-1dc6-61b8-cebd00fa06a1"
2085  
2086 =back
2087  
2088 =cut
2089  
2090 =head1 AUTHORS
2091  
2092 Awncorp, C<awncorp@cpan.org>
2093  
2094 =cut
2095  
2096 =head1 LICENSE
2097  
2098 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
2099  
2100 This program is free software, you can redistribute it and/or modify it under
2101 the terms of the Apache license version 2.0.
2102  
2103 =cut
« blib/lib/Venus/Match.pm ↑ Summary blib/lib/Venus/Array.pm »