line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Venus::Random; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
710
|
use 5.018; |
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Venus::Class 'base', 'with'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
base 'Venus::Kind::Utility'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Venus::Role::Valuable'; |
13
|
|
|
|
|
|
|
with 'Venus::Role::Buildable'; |
14
|
|
|
|
|
|
|
with 'Venus::Role::Accessible'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# STATE |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
state $ORIG_SEED = srand; |
19
|
|
|
|
|
|
|
state $SELF_SEED = substr(((time ^ $$) ** 2), 0, length($ORIG_SEED)); |
20
|
|
|
|
|
|
|
srand $ORIG_SEED; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# BUILDERS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub build_self { |
25
|
80
|
|
|
80
|
0
|
196
|
my ($self, $data) = @_; |
26
|
|
|
|
|
|
|
|
27
|
80
|
|
|
|
|
240
|
$self->reseed($self->value); |
28
|
|
|
|
|
|
|
|
29
|
80
|
|
|
|
|
218
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub assertion { |
35
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my $assert = $self->SUPER::assertion; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
$assert->clear->expression('number'); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
return $assert; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub bit { |
45
|
52
|
|
|
52
|
1
|
114
|
my ($self) = @_; |
46
|
|
|
|
|
|
|
|
47
|
52
|
|
|
|
|
163
|
return $self->select([1, 0]); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub boolean { |
51
|
51
|
|
|
51
|
1
|
112
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
51
|
|
|
|
|
149
|
return $self->select([true, false]); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub byte { |
57
|
51
|
|
|
51
|
1
|
119
|
my ($self) = @_; |
58
|
|
|
|
|
|
|
|
59
|
51
|
|
|
|
|
117
|
return chr(int($self->pick * 256)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub character { |
63
|
663
|
|
|
663
|
1
|
1083
|
my ($self) = @_; |
64
|
|
|
|
|
|
|
|
65
|
663
|
|
|
|
|
1579
|
my $code = $self->select(['digit', 'letter', 'symbol']); |
66
|
|
|
|
|
|
|
|
67
|
663
|
|
|
|
|
1563
|
return $self->$code; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub collect { |
71
|
204
|
|
|
204
|
1
|
526
|
my ($self, $times, $code, @args) = @_; |
72
|
|
|
|
|
|
|
|
73
|
204
|
|
|
|
|
541
|
return scalar($self->repeat($times, $code, @args)); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub digit { |
77
|
1016
|
|
|
1016
|
1
|
1574
|
my ($self) = @_; |
78
|
|
|
|
|
|
|
|
79
|
1016
|
|
|
|
|
2040
|
return int($self->pick(10)); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub float { |
83
|
306
|
|
|
306
|
1
|
60322
|
my ($self, $place, $from, $upto) = @_; |
84
|
|
|
|
|
|
|
|
85
|
306
|
|
100
|
|
|
1125
|
$from //= 0; |
86
|
306
|
|
100
|
|
|
814
|
$upto //= $self->number; |
87
|
|
|
|
|
|
|
|
88
|
306
|
50
|
0
|
|
|
405
|
my $tmp; $tmp = $from and $from = $upto and $upto = $tmp if $from > $upto; |
|
306
|
|
0
|
|
|
621
|
|
89
|
|
|
|
|
|
|
|
90
|
306
|
|
66
|
|
|
777
|
$place //= $self->nonzero; |
91
|
|
|
|
|
|
|
|
92
|
306
|
|
|
|
|
3247
|
return sprintf("%.${place}f", $from + rand() * ($upto - $from)); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub letter { |
96
|
540
|
|
|
540
|
1
|
894
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
|
98
|
540
|
|
|
|
|
1207
|
my $code = $self->select(['uppercased', 'lowercased']); |
99
|
|
|
|
|
|
|
|
100
|
540
|
|
|
|
|
1293
|
return $self->$code; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub lowercased { |
104
|
317
|
|
|
317
|
1
|
511
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
|
106
|
317
|
|
|
|
|
569
|
return lc(chr($self->range(97, 122))); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub pick { |
110
|
4294
|
|
|
4294
|
1
|
97457
|
my ($self, $data) = @_; |
111
|
|
|
|
|
|
|
|
112
|
4294
|
100
|
|
|
|
18400
|
return $data ? rand($data) : rand; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub nonzero { |
116
|
385
|
|
|
385
|
1
|
60453
|
my ($self, $code, @args) = @_; |
117
|
|
|
|
|
|
|
|
118
|
385
|
|
100
|
|
|
1221
|
$code ||= 'digit'; |
119
|
|
|
|
|
|
|
|
120
|
385
|
|
|
|
|
998
|
my $value = $self->$code(@args); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
return |
123
|
385
|
100
|
33
|
|
|
2852
|
($value < 0 && $value > -1) ? ($value + -1) |
|
|
100
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
124
|
|
|
|
|
|
|
: (($value < 1 && $value > 0) ? ($value + 1) |
125
|
|
|
|
|
|
|
: ($value == 0 ? $self->nonzero : $value)); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub number { |
129
|
510
|
|
|
510
|
1
|
31535
|
my ($self, $from, $upto) = @_; |
130
|
|
|
|
|
|
|
|
131
|
510
|
|
100
|
|
|
1764
|
$upto //= 0; |
132
|
510
|
|
100
|
|
|
1300
|
$from //= $self->digit; |
133
|
|
|
|
|
|
|
|
134
|
510
|
100
|
|
|
|
1200
|
return $self->range($from, $upto) if $upto; |
135
|
|
|
|
|
|
|
|
136
|
357
|
50
|
|
|
|
1119
|
return int($self->pick(10 ** ($from > 9 ? 9 : $from) -1)); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub range { |
140
|
2666
|
|
|
2666
|
1
|
4322
|
my ($self, $from, $upto) = @_; |
141
|
|
|
|
|
|
|
|
142
|
2666
|
50
|
|
|
|
4851
|
return 0 if !defined $from; |
143
|
2666
|
50
|
33
|
|
|
5171
|
return 0 if !defined $upto && $from == 0; |
144
|
|
|
|
|
|
|
|
145
|
2666
|
50
|
|
|
|
4179
|
return $from if $from == $upto; |
146
|
|
|
|
|
|
|
|
147
|
2666
|
|
|
|
|
3362
|
my $ceil = 2147483647; |
148
|
|
|
|
|
|
|
|
149
|
2666
|
100
|
66
|
|
|
5966
|
$from = 0 if !$from || $from > $ceil; |
150
|
2666
|
50
|
33
|
|
|
7719
|
$upto = $ceil if !$upto || $upto > $ceil; |
151
|
|
|
|
|
|
|
|
152
|
2666
|
|
|
|
|
5320
|
return $from + int($self->pick(($upto-$from) + 1)); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub repeat { |
156
|
332
|
|
|
332
|
1
|
29996
|
my ($self, $times, $code, @args) = @_; |
157
|
|
|
|
|
|
|
|
158
|
332
|
|
|
|
|
547
|
my @values; |
159
|
|
|
|
|
|
|
|
160
|
332
|
|
100
|
|
|
1029
|
$code ||= 'digit'; |
161
|
332
|
|
100
|
|
|
755
|
$times ||= 1; |
162
|
|
|
|
|
|
|
|
163
|
332
|
|
|
|
|
1694
|
push @values, $self->$code(@args) for 1..$times; |
164
|
|
|
|
|
|
|
|
165
|
332
|
100
|
|
|
|
3192
|
return wantarray ? (@values) : join('', @values); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub reseed { |
169
|
84
|
|
|
84
|
1
|
191
|
my ($self, $seed) = @_; |
170
|
|
|
|
|
|
|
|
171
|
84
|
100
|
66
|
|
|
850
|
my $THIS_SEED = !$seed || $seed =~ /\D/ ? $SELF_SEED : $seed; |
172
|
|
|
|
|
|
|
|
173
|
84
|
|
|
|
|
241
|
$self->value($THIS_SEED); |
174
|
|
|
|
|
|
|
|
175
|
84
|
|
|
|
|
224
|
srand $THIS_SEED; |
176
|
|
|
|
|
|
|
|
177
|
84
|
|
|
|
|
193
|
return $self; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub reset { |
181
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
182
|
|
|
|
|
|
|
|
183
|
1
|
|
|
|
|
6
|
$self->reseed($SELF_SEED); |
184
|
|
|
|
|
|
|
|
185
|
1
|
|
|
|
|
4
|
srand $SELF_SEED; |
186
|
|
|
|
|
|
|
|
187
|
1
|
|
|
|
|
11
|
return $self; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub restore { |
191
|
1
|
|
|
1
|
1
|
4
|
my ($self) = @_; |
192
|
|
|
|
|
|
|
|
193
|
1
|
|
|
|
|
4
|
$self->reseed($ORIG_SEED); |
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
2
|
srand $ORIG_SEED; |
196
|
|
|
|
|
|
|
|
197
|
1
|
|
|
|
|
15
|
return $self; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub select { |
201
|
1666
|
|
|
1666
|
1
|
2577
|
my ($self, $data) = @_; |
202
|
|
|
|
|
|
|
|
203
|
1666
|
100
|
|
|
|
4098
|
if (UNIVERSAL::isa($data, 'ARRAY')) { |
204
|
1615
|
|
|
|
|
2119
|
my $keys = @$data; |
205
|
1615
|
50
|
|
|
|
3710
|
my $rand = $self->range(0, $keys <= 0 ? 0 : $keys - 1); |
206
|
1615
|
|
|
|
|
5525
|
return (@$data)[$rand]; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
51
|
50
|
|
|
|
135
|
if (UNIVERSAL::isa($data, 'HASH')) { |
210
|
51
|
|
|
|
|
120
|
my $keys = keys(%$data); |
211
|
51
|
50
|
|
|
|
186
|
my $rand = $self->range(0, $keys <= 0 ? 0 : $keys - 1); |
212
|
51
|
|
|
|
|
526
|
return $$data{(sort keys %$data)[$rand]}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
0
|
return undef; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub symbol { |
219
|
258
|
|
|
258
|
1
|
444
|
my ($self) = @_; |
220
|
|
|
|
|
|
|
|
221
|
258
|
|
|
|
|
372
|
state $symbols = [split //, q(~!@#$%^&*\(\)-_=+[]{}\|;:'",./<>?)]; |
222
|
|
|
|
|
|
|
|
223
|
258
|
|
|
|
|
467
|
return $self->select($symbols); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub uppercased { |
227
|
325
|
|
|
325
|
1
|
564
|
my ($self) = @_; |
228
|
|
|
|
|
|
|
|
229
|
325
|
|
|
|
|
530
|
return uc(chr($self->range(97, 122))); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
1; |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 NAME |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Venus::Random - Random Class |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 ABSTRACT |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Random Class for Perl 5 |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 SYNOPSIS |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
package main; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
use Venus::Random; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $random = Venus::Random->new(42); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# my $bit = $random->bit; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# 1 |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=cut |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 DESCRIPTION |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
This package provides an object-oriented interface for Perl's pseudo-random |
265
|
|
|
|
|
|
|
number generator (or PRNG) which produces a deterministic sequence of bits |
266
|
|
|
|
|
|
|
which approximate true randomness. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 INHERITS |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
This package inherits behaviors from: |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
L |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 INTEGRATES |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
This package integrates behaviors from: |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
L |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
L |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
L |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 METHODS |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
This package provides the following methods: |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=cut |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head2 bit |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
bit() (Int) |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
The bit method returns a C<1> or C<0> value, randomly. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
I> |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=over 4 |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=item bit example 1 |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# given: synopsis |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
package main; |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
my $bit = $random->bit; |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# 0 |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# $bit = $random->bit; |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# 1 |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=back |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=cut |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head2 boolean |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
boolean() (Bool) |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
The boolean method returns a C or C value, randomly. |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
I> |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=over 4 |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=item boolean example 1 |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# given: synopsis |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
package main; |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
my $boolean = $random->boolean; |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
# 0 |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
# $boolean = $random->boolean; |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
# 1 |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=back |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=cut |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=head2 byte |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
byte() (Str) |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
The byte method returns random byte characters, randomly. |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
I> |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=over 4 |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=item byte example 1 |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
# given: synopsis |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
package main; |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
my $byte = $random->byte; |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
# "\xBE" |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
# $byte = $random->byte; |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
# "W" |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=back |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
=cut |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=head2 character |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
character() (Str) |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
The character method returns a random character, which is either a L, |
385
|
|
|
|
|
|
|
L, or L value. |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
I> |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
=over 4 |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
=item character example 1 |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
# given: synopsis |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
package main; |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
my $character = $random->character; |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
# ")" |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
# $character = $random->character; |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
# 4 |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=back |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
=cut |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
=head2 collect |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
collect(Int $times, Str|CodeRef $code, Any @args) (Int|Str) |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
The collect method dispatches to the specified method or coderef, repeatedly |
414
|
|
|
|
|
|
|
based on the number of C<$times> specified, and returns the random concatenated |
415
|
|
|
|
|
|
|
results from each dispatched call. By default, if no arguments are provided, |
416
|
|
|
|
|
|
|
this method dispatches to L. |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
I> |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=over 4 |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=item collect example 1 |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
# given: synopsis |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
package main; |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
my $collect = $random->collect; |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
# 7 |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
# $collect = $random->collect; |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
# 3 |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
=back |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
=over 4 |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=item collect example 2 |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
# given: synopsis |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
package main; |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
my $collect = $random->collect(2); |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
# 73 |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
# $collect = $random->collect(2); |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# 14 |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=back |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
=over 4 |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=item collect example 3 |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
# given: synopsis |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
package main; |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
my $collect = $random->collect(5, "letter"); |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
# "iKWMv" |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
# $collect = $random->collect(5, "letter"); |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
# "Papmm" |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=back |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
=over 4 |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
=item collect example 4 |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# given: synopsis |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
package main; |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
my $collect = $random->collect(10, "character"); |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
# ")48R+a}[Lb" |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# $collect = $random->collect(10, "character"); |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
# "?&0725^,0w" |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
=back |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
=cut |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
=head2 digit |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
digit() (Int) |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
The digit method returns a random digit between C<0> and C<9>. |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
I> |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=over 4 |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=item digit example 1 |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
# given: synopsis |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
package main; |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
my $digit = $random->digit; |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
# 7 |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
# $digit = $random->digit; |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
# 3 |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=back |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
=cut |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=head2 float |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
float(Int $place, Int $from, Int $upto) (Num) |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
The float method returns a random float. |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
I> |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
=over 4 |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=item float example 1 |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
# given: synopsis |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
package main; |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
my $float = $random->float; |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
# 1447361.5 |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
# $float = $random->float; |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
# "0.0000" |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=back |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=over 4 |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=item float example 2 |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
# given: synopsis |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
package main; |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
my $float = $random->float(2); |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
# 380690.82 |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
# $float = $random->float(2); |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
# 694.57 |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
=back |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
=over 4 |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=item float example 3 |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
# given: synopsis |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
package main; |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
my $float = $random->float(2, 1, 5); |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
# 3.98 |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
# $float = $random->float(2, 1, 5); |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
# 2.37 |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=back |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=over 4 |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=item float example 4 |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
# given: synopsis |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
package main; |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
my $float = $random->float(3, 1, 2); |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
# 1.745 |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
# $float = $random->float(3, 1, 2); |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
# 1.343 |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
=back |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
=cut |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
=head2 letter |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
letter() (Str) |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
The letter method returns a random letter, which is either an L or |
612
|
|
|
|
|
|
|
L value. |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
I> |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=over 4 |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
=item letter example 1 |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
# given: synopsis |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
package main; |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
my $letter = $random->letter; |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
# "i" |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
# $letter = $random->letter; |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
# "K" |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=back |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=cut |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
=head2 lowercased |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
lowercased() (Str) |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
The lowercased method returns a random lowercased letter. |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
I> |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=over 4 |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
=item lowercased example 1 |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
# given: synopsis |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
package main; |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
my $lowercased = $random->lowercased; |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
# "t" |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
# $lowercased = $random->lowercased; |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
# "i" |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
=back |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
=cut |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=head2 nonzero |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
nonzero(Str|CodeRef $code, Any @args) (Int|Str) |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
The nonzero method dispatches to the specified method or coderef and returns |
669
|
|
|
|
|
|
|
the random value ensuring that it's never zero, not even a percentage of zero. |
670
|
|
|
|
|
|
|
By default, if no arguments are provided, this method dispatches to L. |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
I> |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
=over 4 |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
=item nonzero example 1 |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
# given: synopsis |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
package main; |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
my $nonzero = $random->nonzero; |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
# 7 |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
# $nonzero = $random->nonzero; |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
# 3 |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
=back |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=over 4 |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
=item nonzero example 2 |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
# given: synopsis |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
package main; |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
my $nonzero = $random->nonzero("pick"); |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
# 1.74452500006101 |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
# $nonzero = $random->nonzero("pick"); |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
# 1.34270147871891 |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
=back |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
=over 4 |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=item nonzero example 3 |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
# given: synopsis |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
package main; |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
my $nonzero = $random->nonzero("number"); |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
# 3427014 |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
# $nonzero = $random->nonzero("number"); |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
# 3 |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
=back |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
=over 4 |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
=item nonzero example 4 |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
# given: synopsis |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
package main; |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
my $nonzero = $random->nonzero("number", 0, 10); |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
# 8 |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
# $nonzero = $random->nonzero("number", 0, 10); |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
# 3 |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
=back |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
=cut |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
=head2 number |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
number(Int $from, Int $upto) (Num) |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
The number method returns a random number within the range provided. If no |
753
|
|
|
|
|
|
|
arguments are provided, the range is from C<0> to C<2147483647>. If only the |
754
|
|
|
|
|
|
|
first argument is provided, it's treated as the desired length of the number. |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
I> |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=over 4 |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=item number example 1 |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
# given: synopsis |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
package main; |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
my $number = $random->number; |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
# 3427014 |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
# $number = $random->number; |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
# 3 |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
=back |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
=over 4 |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
=item number example 2 |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
# given: synopsis |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
package main; |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
my $number = $random->number(5, 50); |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
# 39 |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
# $number = $random->number(5, 50); |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
# 20 |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
=back |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
=over 4 |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
=item number example 3 |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
# given: synopsis |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
package main; |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
my $number = $random->number(100, 20); |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
# 42 |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
# $number = $random->number(100, 20); |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
# 73 |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
=back |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
=over 4 |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
=item number example 4 |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
# given: synopsis |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
package main; |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
my $number = $random->number(5); |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
# 74451 |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
# $number = $random->number(5); |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
# 34269 |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
=back |
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
=cut |
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
=head2 pick |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
pick(Num $data) (Num) |
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
The pick method is the random number generator and returns a random number. By |
837
|
|
|
|
|
|
|
default, calling this method is equivalent to call L. This |
838
|
|
|
|
|
|
|
method can be overridden in a subclass to provide a custom generator, e.g. a |
839
|
|
|
|
|
|
|
more cyptographically secure generator. |
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
I> |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
=over 4 |
844
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
=item pick example 1 |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
# given: synopsis |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
package main; |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
my $pick = $random->pick; |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
# 0.744525000061007 |
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
# $pick = $random->pick; |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
# 0.342701478718908 |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
=back |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
=over 4 |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
=item pick example 2 |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
# given: synopsis |
866
|
|
|
|
|
|
|
|
867
|
|
|
|
|
|
|
package main; |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
my $pick = $random->pick(100); |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
# 74.4525000061007 |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
# $pick = $random->pick(100); |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
# 34.2701478718908 |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
=back |
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
=over 4 |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
=item pick example 3 |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
# given: synopsis |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
package main; |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
my $pick = $random->pick(2); |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
# 1.48905000012201 |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
# $pick = $random->pick(2); |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
# 0.685402957437816 |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
=back |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
=cut |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
=head2 range |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
range(Str $from, Str $to) (Int) |
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
The range method returns a random number within the range provided. If no |
904
|
|
|
|
|
|
|
arguments are provided, the range is from C<0> to C<2147483647>. |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
I> |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
=over 4 |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
=item range example 1 |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
# given: synopsis |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
package main; |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
my $range = $random->range(1, 10); |
917
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
# 8 |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
# $range = $random->range(1, 10); |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
# 4 |
923
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
=back |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
=over 4 |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
=item range example 2 |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
# given: synopsis |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
package main; |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
my $range = $random->range(10, 1); |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
# 5 |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
# $range = $random->range(10, 1); |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
# 8 |
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
=back |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
=over 4 |
945
|
|
|
|
|
|
|
|
946
|
|
|
|
|
|
|
=item range example 3 |
947
|
|
|
|
|
|
|
|
948
|
|
|
|
|
|
|
# given: synopsis |
949
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
package main; |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
my $range = $random->range(0, 60); |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
# 45 |
955
|
|
|
|
|
|
|
|
956
|
|
|
|
|
|
|
# $range = $random->range(0, 60); |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
# 20 |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
=back |
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
=over 4 |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
=item range example 4 |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
# given: synopsis |
967
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
package main; |
969
|
|
|
|
|
|
|
|
970
|
|
|
|
|
|
|
my $range = $random->range(-5, -1); |
971
|
|
|
|
|
|
|
|
972
|
|
|
|
|
|
|
# -2 |
973
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
# $range = $random->range(-5, -1); |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
# -4 |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
=back |
979
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
=cut |
981
|
|
|
|
|
|
|
|
982
|
|
|
|
|
|
|
=head2 repeat |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
repeat(Int $times, Str|CodeRef $code, Any @args) (Int|Str) |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
The repeat method dispatches to the specified method or coderef, repeatedly |
987
|
|
|
|
|
|
|
based on the number of C<$times> specified, and returns the random results from |
988
|
|
|
|
|
|
|
each dispatched call. In list context, the results from each call is returned |
989
|
|
|
|
|
|
|
as a list, in scalar context the results are concatenated. |
990
|
|
|
|
|
|
|
|
991
|
|
|
|
|
|
|
I> |
992
|
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
=over 4 |
994
|
|
|
|
|
|
|
|
995
|
|
|
|
|
|
|
=item repeat example 1 |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
# given: synopsis |
998
|
|
|
|
|
|
|
|
999
|
|
|
|
|
|
|
package main; |
1000
|
|
|
|
|
|
|
|
1001
|
|
|
|
|
|
|
my @repeat = $random->repeat(2); |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
# (7, 3) |
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
# @repeat = $random->repeat(2); |
1006
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
# (1, 4) |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
=back |
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
=over 4 |
1015
|
|
|
|
|
|
|
|
1016
|
|
|
|
|
|
|
=item repeat example 2 |
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
# given: synopsis |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
package main; |
1021
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
my @repeat = $random->repeat(2, "float"); |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
# (1447361.5, "0.0000") |
1025
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
# @repeat = $random->repeat(2, "float"); |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
# ("482092.1040", 1555.7410393) |
1029
|
|
|
|
|
|
|
|
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
|
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
=back |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=over 4 |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
=item repeat example 3 |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
# given: synopsis |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
package main; |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
my @repeat = $random->repeat(2, "character"); |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
# (")", 4) |
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
# @repeat = $random->repeat(2, "character"); |
1048
|
|
|
|
|
|
|
|
1049
|
|
|
|
|
|
|
# (8, "R") |
1050
|
|
|
|
|
|
|
|
1051
|
|
|
|
|
|
|
=back |
1052
|
|
|
|
|
|
|
|
1053
|
|
|
|
|
|
|
=cut |
1054
|
|
|
|
|
|
|
|
1055
|
|
|
|
|
|
|
=head2 reseed |
1056
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
reseed(Str $seed) (Random) |
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
The reseed method sets the L (i.e. the PRNG seed) to the value |
1060
|
|
|
|
|
|
|
provided, or the default value used on instanstiation when no seed is passed to |
1061
|
|
|
|
|
|
|
the constructor. This method returns the object that invoked it. |
1062
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
I> |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
=over 4 |
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
=item reseed example 1 |
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
# given: synopsis |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
package main; |
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
my $reseed = $random->reseed; |
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
# bless({value => ...}, "Venus::Random") |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
# my $bit = $random->bit; |
1078
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
# 0 |
1080
|
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
|
=back |
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
=over 4 |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
=item reseed example 2 |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
# given: synopsis |
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
package main; |
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
my $reseed = $random->reseed(42); |
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
# bless({value => 42}, "Venus::Random") |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
# my $bit = $random->bit; |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
# 0 |
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
=back |
1100
|
|
|
|
|
|
|
|
1101
|
|
|
|
|
|
|
=cut |
1102
|
|
|
|
|
|
|
|
1103
|
|
|
|
|
|
|
=head2 reset |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
reset() (Random) |
1106
|
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
|
The reset method sets the L (i.e. the PRNG seed) to the default |
1108
|
|
|
|
|
|
|
value used on instanstiation when no seed is passed to the constructor. This |
1109
|
|
|
|
|
|
|
method returns the object that invoked it. |
1110
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
I> |
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
=over 4 |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
=item reset example 1 |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
# given: synopsis |
1118
|
|
|
|
|
|
|
|
1119
|
|
|
|
|
|
|
package main; |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
my $reset = $random->reset; |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
# bless({value => ...}, "Venus::Random") |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
=back |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
=cut |
1128
|
|
|
|
|
|
|
|
1129
|
|
|
|
|
|
|
=head2 restore |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
restore() (Random) |
1132
|
|
|
|
|
|
|
|
1133
|
|
|
|
|
|
|
The restore method sets the L (i.e. the PRNG seed) to the |
1134
|
|
|
|
|
|
|
original value used by L. This method returns the object that |
1135
|
|
|
|
|
|
|
invoked it. |
1136
|
|
|
|
|
|
|
|
1137
|
|
|
|
|
|
|
I> |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
=over 4 |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
=item restore example 1 |
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
# given: synopsis |
1144
|
|
|
|
|
|
|
|
1145
|
|
|
|
|
|
|
package main; |
1146
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
my $restore = $random->restore; |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
# bless({value => ...}, "Venus::Random") |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
=back |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
=cut |
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
=head2 select |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
select(ArrayRef|HashRef $data) (Any) |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
The select method returns a random value from the I<"hashref"> or I<"arrayref"> |
1160
|
|
|
|
|
|
|
provided. |
1161
|
|
|
|
|
|
|
|
1162
|
|
|
|
|
|
|
I> |
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
=over 4 |
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
=item select example 1 |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
# given: synopsis |
1169
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
package main; |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
my $select = $random->select(["a".."d"]); |
1173
|
|
|
|
|
|
|
|
1174
|
|
|
|
|
|
|
# "c" |
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
# $select = $random->select(["a".."d"]); |
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
# "b" |
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
=back |
1181
|
|
|
|
|
|
|
|
1182
|
|
|
|
|
|
|
=over 4 |
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
=item select example 2 |
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
# given: synopsis |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
package main; |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
my $select = $random->select({"a".."h"}); |
1191
|
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
|
# "f" |
1193
|
|
|
|
|
|
|
|
1194
|
|
|
|
|
|
|
# $select = $random->select({"a".."h"}); |
1195
|
|
|
|
|
|
|
|
1196
|
|
|
|
|
|
|
# "d" |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
=back |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
=cut |
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
=head2 symbol |
1203
|
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
symbol() (Str) |
1205
|
|
|
|
|
|
|
|
1206
|
|
|
|
|
|
|
The symbol method returns a random symbol. |
1207
|
|
|
|
|
|
|
|
1208
|
|
|
|
|
|
|
I> |
1209
|
|
|
|
|
|
|
|
1210
|
|
|
|
|
|
|
=over 4 |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
=item symbol example 1 |
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
# given: synopsis |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
package main; |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
my $symbol = $random->symbol; |
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
# "'" |
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
# $symbol = $random->symbol; |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
# ")" |
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
=back |
1227
|
|
|
|
|
|
|
|
1228
|
|
|
|
|
|
|
=cut |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
=head2 uppercased |
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
uppercased() (Str) |
1233
|
|
|
|
|
|
|
|
1234
|
|
|
|
|
|
|
The uppercased method returns a random uppercased letter. |
1235
|
|
|
|
|
|
|
|
1236
|
|
|
|
|
|
|
I> |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
=over 4 |
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
=item uppercased example 1 |
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
# given: synopsis |
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
package main; |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
my $uppercased = $random->uppercased; |
1247
|
|
|
|
|
|
|
|
1248
|
|
|
|
|
|
|
# "T" |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
# $uppercased = $random->uppercased; |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
# "I" |
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
=back |
1255
|
|
|
|
|
|
|
|
1256
|
|
|
|
|
|
|
=cut |
1257
|
|
|
|
|
|
|
|
1258
|
|
|
|
|
|
|
=head1 AUTHORS |
1259
|
|
|
|
|
|
|
|
1260
|
|
|
|
|
|
|
Awncorp, C |
1261
|
|
|
|
|
|
|
|
1262
|
|
|
|
|
|
|
=cut |
1263
|
|
|
|
|
|
|
|
1264
|
|
|
|
|
|
|
=head1 LICENSE |
1265
|
|
|
|
|
|
|
|
1266
|
|
|
|
|
|
|
Copyright (C) 2000, Al Newkirk. |
1267
|
|
|
|
|
|
|
|
1268
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
1269
|
|
|
|
|
|
|
the terms of the Apache license version 2.0. |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
=cut |