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