line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################ |
2
|
|
|
|
|
|
|
# Data::Random |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# A module used to generate random data. |
5
|
|
|
|
|
|
|
################################################################################ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Data::Random; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
################################################################################ |
10
|
|
|
|
|
|
|
# - Modules and Libraries |
11
|
|
|
|
|
|
|
################################################################################ |
12
|
9
|
|
|
9
|
|
116545
|
use strict; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
253
|
|
13
|
9
|
|
|
9
|
|
29
|
use warnings; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
169
|
|
14
|
9
|
|
|
9
|
|
127
|
use 5.005_62; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
214
|
|
15
|
|
|
|
|
|
|
|
16
|
9
|
|
|
9
|
|
26
|
use Carp qw(cluck); |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
591
|
|
17
|
9
|
|
|
9
|
|
4171
|
use Time::Piece; |
|
9
|
|
|
|
|
79979
|
|
|
9
|
|
|
|
|
34
|
|
18
|
|
|
|
|
|
|
#use Data::Random::WordList; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Exporter; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
################################################################################ |
23
|
|
|
|
|
|
|
# - Global Constants and Variables |
24
|
|
|
|
|
|
|
################################################################################ |
25
|
9
|
|
|
|
|
15207
|
use vars qw( |
26
|
|
|
|
|
|
|
@ISA |
27
|
|
|
|
|
|
|
%EXPORT_TAGS |
28
|
|
|
|
|
|
|
@EXPORT_OK |
29
|
|
|
|
|
|
|
@EXPORT |
30
|
9
|
|
|
9
|
|
560
|
); |
|
9
|
|
|
|
|
12
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
35
|
|
|
|
|
|
|
'all' => [ |
36
|
|
|
|
|
|
|
qw( |
37
|
|
|
|
|
|
|
rand_words |
38
|
|
|
|
|
|
|
rand_chars |
39
|
|
|
|
|
|
|
rand_set |
40
|
|
|
|
|
|
|
rand_enum |
41
|
|
|
|
|
|
|
rand_date |
42
|
|
|
|
|
|
|
rand_time |
43
|
|
|
|
|
|
|
rand_datetime |
44
|
|
|
|
|
|
|
rand_image |
45
|
|
|
|
|
|
|
) |
46
|
|
|
|
|
|
|
] |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
50
|
|
|
|
|
|
|
@EXPORT = qw(); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$Data::Random::VERSION = '0.11_3'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
################################################################################ |
55
|
|
|
|
|
|
|
# - Subroutines |
56
|
|
|
|
|
|
|
################################################################################ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
################################################################################ |
59
|
|
|
|
|
|
|
# rand_words() |
60
|
|
|
|
|
|
|
################################################################################ |
61
|
|
|
|
|
|
|
sub rand_words { |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Get the options hash |
64
|
130
|
|
|
130
|
1
|
4547
|
my %options = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Initialize max and min vars |
67
|
130
|
|
100
|
|
|
387
|
$options{'min'} ||= 1; |
68
|
130
|
|
100
|
|
|
273
|
$options{'max'} ||= 1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Initialize the wordlist param |
71
|
130
|
|
50
|
|
|
211
|
$options{'wordlist'} ||= ''; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Make sure the max and min vars are OK |
74
|
130
|
50
|
0
|
|
|
192
|
cluck('min value cannot be larger than max value') && return |
75
|
|
|
|
|
|
|
if $options{'min'} > $options{'max'}; |
76
|
130
|
50
|
0
|
|
|
401
|
cluck('min value must be a positive integer') && return |
|
|
|
33
|
|
|
|
|
77
|
|
|
|
|
|
|
if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} ); |
78
|
130
|
50
|
0
|
|
|
372
|
cluck('max value must be a positive integer') && return |
|
|
|
33
|
|
|
|
|
79
|
|
|
|
|
|
|
if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Initialize the size var |
82
|
130
|
|
66
|
|
|
294
|
$options{'size'} ||= |
83
|
|
|
|
|
|
|
int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Make sure the size var is OK |
86
|
130
|
50
|
0
|
|
|
359
|
cluck('size value must be a positive integer') && return |
|
|
|
33
|
|
|
|
|
87
|
|
|
|
|
|
|
if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Initialize the shuffle flag |
90
|
130
|
100
|
|
|
|
195
|
$options{'shuffle'} = |
91
|
|
|
|
|
|
|
exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1; |
92
|
|
|
|
|
|
|
|
93
|
130
|
|
|
|
|
102
|
my $wl; |
94
|
130
|
|
|
|
|
82
|
my $close_wl = 1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Check for a pre-existing wordlist object |
97
|
130
|
50
|
|
|
|
147
|
if ( ref( $options{'wordlist'} ) ) { |
98
|
0
|
|
|
|
|
0
|
$wl = $options{'wordlist'}; |
99
|
0
|
|
|
|
|
0
|
$close_wl = 0; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
130
|
|
|
|
|
952
|
require Data::Random::WordList; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Create a new wordlist object |
105
|
130
|
|
|
|
|
465
|
$wl = Data::Random::WordList->new( wordlist => $options{'wordlist'} ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Get the random words |
109
|
130
|
|
|
|
|
286
|
my $rand_words = $wl->get_words( $options{'size'} ); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Close the word list |
112
|
130
|
50
|
|
|
|
400
|
$wl->close() if $close_wl; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Shuffle the words around |
115
|
130
|
100
|
|
|
|
1183
|
_shuffle($rand_words) if $options{'shuffle'}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Return an array or an array reference, depending on the context in which the sub was called |
118
|
130
|
50
|
|
|
|
200
|
if ( wantarray() ) { |
119
|
130
|
|
|
|
|
910
|
return @$rand_words; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
|
|
|
|
0
|
return $rand_words; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
################################################################################ |
127
|
|
|
|
|
|
|
# rand_chars() |
128
|
|
|
|
|
|
|
################################################################################ |
129
|
|
|
|
|
|
|
sub rand_chars { |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Get the options hash |
132
|
3020
|
|
|
3020
|
1
|
138491
|
my %options = @_; |
133
|
3020
|
|
|
|
|
2123
|
my @chars; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Build named character sets if one wasn't supplied |
136
|
3020
|
100
|
|
|
|
5161
|
if ( ref( $options{'set'} ) ne 'ARRAY' ) { |
137
|
302
|
|
|
|
|
290
|
my @charset = (); |
138
|
|
|
|
|
|
|
|
139
|
302
|
100
|
|
|
|
739
|
if ( $options{'set'} eq 'all' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
140
|
94
|
|
|
|
|
825
|
@charset = |
141
|
|
|
|
|
|
|
( 0 .. 9, 'a' .. 'z', 'A' .. 'Z', '#', ',', |
142
|
|
|
|
|
|
|
qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `) |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
elsif ( $options{'set'} eq 'alpha' ) { |
146
|
52
|
|
|
|
|
292
|
@charset = ( 'a' .. 'z', 'A' .. 'Z' ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
elsif ( $options{'set'} eq 'upperalpha' ) { |
149
|
26
|
|
|
|
|
89
|
@charset = ( 'A' .. 'Z' ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
elsif ( $options{'set'} eq 'loweralpha' ) { |
152
|
26
|
|
|
|
|
102
|
@charset = ( 'a' .. 'z' ); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
elsif ( $options{'set'} eq 'numeric' ) { |
155
|
10
|
|
|
|
|
16
|
@charset = ( 0 .. 9 ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
elsif ( $options{'set'} eq 'alphanumeric' ) { |
158
|
62
|
|
|
|
|
395
|
@charset = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' ); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
elsif ( $options{'set'} eq 'misc' ) { |
161
|
32
|
|
|
|
|
108
|
@charset = |
162
|
|
|
|
|
|
|
( '#', ',', |
163
|
|
|
|
|
|
|
qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `) |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
302
|
|
|
|
|
433
|
$options{'set'} = \@charset; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
3020
|
|
|
|
|
4478
|
@chars = rand_set(%options); |
171
|
3020
|
100
|
|
|
|
17458
|
return wantarray ? @chars : join('', @chars); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
################################################################################ |
175
|
|
|
|
|
|
|
# rand_set() |
176
|
|
|
|
|
|
|
################################################################################ |
177
|
|
|
|
|
|
|
sub rand_set { |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Get the options hash |
180
|
3164
|
|
|
3164
|
1
|
7584
|
my %options = @_; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# Make sure the set array was defined |
183
|
3164
|
50
|
0
|
|
|
4527
|
cluck('set array is not defined') && return if !$options{'set'}; |
184
|
|
|
|
|
|
|
|
185
|
3164
|
100
|
66
|
|
|
10021
|
$options{'size'} = 1 |
|
|
|
100
|
|
|
|
|
186
|
|
|
|
|
|
|
unless exists( $options{'min'} ) || exists( $options{'max'} ) |
187
|
|
|
|
|
|
|
|| exists( $options{'size'} ); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# Initialize max and min vars |
190
|
3164
|
|
100
|
|
|
5562
|
$options{'min'} ||= 0; |
191
|
3164
|
|
66
|
|
|
4099
|
$options{'max'} ||= @{ $options{'set'} }; |
|
1898
|
|
|
|
|
3069
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# Make sure the max and min vars are OK |
194
|
3164
|
50
|
0
|
|
|
4523
|
cluck('min value cannot be larger than max value') && return |
195
|
|
|
|
|
|
|
if $options{'min'} > $options{'max'}; |
196
|
3164
|
50
|
0
|
|
|
9149
|
cluck('min value must be a positive integer') && return |
|
|
|
33
|
|
|
|
|
197
|
|
|
|
|
|
|
if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} ); |
198
|
3164
|
50
|
0
|
|
|
8718
|
cluck('max value must be a positive integer') && return |
|
|
|
33
|
|
|
|
|
199
|
|
|
|
|
|
|
if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} ); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# Initialize the size var |
202
|
3164
|
|
66
|
|
|
5320
|
$options{'size'} ||= |
203
|
|
|
|
|
|
|
int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'}; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# Make sure the size var is OK |
206
|
3164
|
50
|
0
|
|
|
8172
|
cluck('size value must be a positive integer') && return |
|
|
|
33
|
|
|
|
|
207
|
|
|
|
|
|
|
if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} ); |
208
|
3164
|
|
|
|
|
4483
|
cluck('size value exceeds set size') && return |
209
|
3164
|
50
|
0
|
|
|
2161
|
if $options{'size'} > @{ $options{'set'} }; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# Initialize the shuffle flag |
212
|
3164
|
100
|
|
|
|
4503
|
$options{'shuffle'} = |
213
|
|
|
|
|
|
|
exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# Get the random items |
216
|
3164
|
|
|
|
|
2912
|
my %results = (); |
217
|
3164
|
|
|
|
|
4810
|
for ( my $i = 0 ; $i < $options{'size'} ; $i++ ) { |
218
|
66458
|
|
|
|
|
41973
|
my $result; |
219
|
|
|
|
|
|
|
|
220
|
66458
|
|
|
|
|
38169
|
do { |
221
|
141600
|
|
|
|
|
78457
|
$result = int( rand( @{ $options{'set'} } ) ); |
|
141600
|
|
|
|
|
233695
|
|
222
|
|
|
|
|
|
|
} while ( exists( $results{$result} ) ); |
223
|
|
|
|
|
|
|
|
224
|
66458
|
|
|
|
|
101488
|
$results{$result} = 1; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
3164
|
|
|
|
|
10731
|
my @results = sort { $a <=> $b } keys %results; |
|
278961
|
|
|
|
|
189714
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# Shuffle the items |
230
|
3164
|
100
|
|
|
|
8547
|
_shuffle( \@results ) if $options{'shuffle'}; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# Return an array or an array reference, depending on the context in which the sub was called |
233
|
3164
|
50
|
|
|
|
3643
|
if ( wantarray() ) { |
234
|
3164
|
|
|
|
|
2317
|
return @{ $options{'set'} }[@results]; |
|
3164
|
|
|
|
|
27019
|
|
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
else { |
237
|
0
|
|
|
|
|
0
|
return \@{ $options{'set'} }[@results]; |
|
0
|
|
|
|
|
0
|
|
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
################################################################################ |
242
|
|
|
|
|
|
|
# rand_enum() |
243
|
|
|
|
|
|
|
################################################################################ |
244
|
|
|
|
|
|
|
sub rand_enum { |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# Get the options hash |
247
|
29
|
|
|
29
|
1
|
146
|
my %options = @_; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# Make sure the set array was defined |
250
|
29
|
50
|
0
|
|
|
33
|
cluck('set array is not defined') && return if !$options{'set'}; |
251
|
|
|
|
|
|
|
|
252
|
29
|
|
|
|
|
18
|
return $options{'set'}->[ int( rand( @{ $options{'set'} } ) ) ]; |
|
29
|
|
|
|
|
117
|
|
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
################################################################################ |
256
|
|
|
|
|
|
|
# rand_date() |
257
|
|
|
|
|
|
|
################################################################################ |
258
|
|
|
|
|
|
|
sub rand_date { |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# Get the options hash |
261
|
5000
|
|
|
5000
|
1
|
5302726
|
my %options = @_; |
262
|
|
|
|
|
|
|
|
263
|
5000
|
|
|
|
|
4783
|
my $min; |
264
|
|
|
|
|
|
|
my $max; |
265
|
|
|
|
|
|
|
# Get today's date |
266
|
5000
|
|
|
|
|
8717
|
my $t = localtime; |
267
|
5000
|
|
|
|
|
193532
|
my ( $year, $month, $day ) = split('-', $t->ymd); |
268
|
5000
|
|
|
|
|
60020
|
my $today = Time::Piece->strptime($t->ymd, "%Y-%m-%d"); |
269
|
|
|
|
|
|
|
|
270
|
5000
|
100
|
|
|
|
101883
|
if ( $options{'min'} ) { |
271
|
4000
|
100
|
|
|
|
5906
|
if ( $options{'min'} eq 'now' ) { |
272
|
1000
|
|
|
|
|
974
|
$min = $today; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
else { |
275
|
3000
|
|
|
|
|
4860
|
$min = Time::Piece->strptime($options{'min'}, '%Y-%m-%d'); |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
else { |
279
|
1000
|
|
|
|
|
1031
|
$min = $today; |
280
|
|
|
|
|
|
|
} |
281
|
5000
|
100
|
|
|
|
38572
|
if ( $options{'max'} ) { |
282
|
2000
|
100
|
|
|
|
2698
|
if ( $options{'max'} eq 'now' ) { |
283
|
1000
|
|
|
|
|
839
|
$max = $today; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
else { |
286
|
1000
|
|
|
|
|
1530
|
$max = Time::Piece->strptime($options{max}, "%Y-%m-%d"); |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
else { |
290
|
3000
|
|
|
|
|
5085
|
$max = $min->add_years(1); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
5000
|
|
|
|
|
99253
|
my $delta_days = int($max->julian_day) - int($min->julian_day); |
294
|
5000
|
50
|
0
|
|
|
151532
|
cluck('max date is later than min date') && return if $delta_days < 0; |
295
|
|
|
|
|
|
|
|
296
|
5000
|
|
|
|
|
13079
|
my $result = $min + ( 3600 * 24 * int( rand($delta_days + 1) ) ); |
297
|
5000
|
|
|
|
|
230624
|
return $result->ymd; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
################################################################################ |
301
|
|
|
|
|
|
|
# rand_time() |
302
|
|
|
|
|
|
|
################################################################################ |
303
|
|
|
|
|
|
|
sub rand_time { |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# Get the options hash |
306
|
1764021
|
|
|
1764021
|
1
|
13129966
|
my %options = @_; |
307
|
|
|
|
|
|
|
|
308
|
1764021
|
|
|
|
|
960111
|
my ( $min_hour, $min_min, $min_sec, $max_hour, $max_min, $max_sec ); |
309
|
|
|
|
|
|
|
|
310
|
1764021
|
100
|
|
|
|
1670340
|
if ( $options{'min'} ) { |
311
|
756011
|
100
|
|
|
|
725624
|
if ( $options{'min'} eq 'now' ) { |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
# Get the current time |
314
|
1
|
|
|
|
|
4
|
my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ]; |
315
|
|
|
|
|
|
|
|
316
|
1
|
|
|
|
|
83
|
( $min_hour, $min_min, $min_sec ) = ( $hour, $min, $sec ); |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
else { |
319
|
756010
|
|
|
|
|
887995
|
( $min_hour, $min_min, $min_sec ) = split ( /\:/, $options{'min'} ); |
320
|
|
|
|
|
|
|
|
321
|
756010
|
50
|
0
|
|
|
1868621
|
cluck('minimum time is not in valid time format HH:MM:SS') && return |
|
|
|
33
|
|
|
|
|
322
|
|
|
|
|
|
|
if ( $min_hour > 23 ) || ( $min_hour < 0 ); |
323
|
756010
|
50
|
0
|
|
|
1636014
|
cluck('minimum time is not in valid time format HH:MM:SS') && return |
|
|
|
33
|
|
|
|
|
324
|
|
|
|
|
|
|
if ( $min_min > 59 ) || ( $min_min < 0 ); |
325
|
756010
|
50
|
0
|
|
|
1642508
|
cluck('minimum time is not in valid time format HH:MM:SS') && return |
|
|
|
33
|
|
|
|
|
326
|
|
|
|
|
|
|
if ( $min_sec > 59 ) || ( $min_sec < 0 ); |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
else { |
330
|
1008010
|
|
|
|
|
704970
|
( $min_hour, $min_min, $min_sec ) = ( 0, 0, 0 ); |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
1764021
|
100
|
|
|
|
1606741
|
if ( $options{'max'} ) { |
334
|
180021
|
100
|
|
|
|
163991
|
if ( $options{'max'} eq 'now' ) { |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# Get the current time |
337
|
1
|
|
|
|
|
3
|
my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ]; |
338
|
|
|
|
|
|
|
|
339
|
1
|
|
|
|
|
25
|
( $max_hour, $max_min, $max_sec ) = ( $hour, $min, $sec ); |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
else { |
342
|
180020
|
|
|
|
|
227517
|
( $max_hour, $max_min, $max_sec ) = split ( /\:/, $options{'max'} ); |
343
|
|
|
|
|
|
|
|
344
|
180020
|
50
|
0
|
|
|
453667
|
cluck('maximum time is not in valid time format HH:MM:SS') && return |
|
|
|
33
|
|
|
|
|
345
|
|
|
|
|
|
|
if ( $max_hour > 23 ) || ( $max_hour < 0 ); |
346
|
180020
|
50
|
0
|
|
|
389624
|
cluck('maximum time is not in valid time format HH:MM:SS') && return |
|
|
|
33
|
|
|
|
|
347
|
|
|
|
|
|
|
if ( $max_min > 59 ) || ( $max_min < 0 ); |
348
|
180020
|
50
|
0
|
|
|
400929
|
cluck('maximum time is not in valid time format HH:MM:SS') && return |
|
|
|
33
|
|
|
|
|
349
|
|
|
|
|
|
|
if ( $max_sec > 59 ) || ( $max_sec < 0 ); |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
else { |
353
|
1584000
|
|
|
|
|
1049052
|
( $max_hour, $max_min, $max_sec ) = ( 23, 59, 59 ); |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
|
356
|
1764021
|
|
|
|
|
1333095
|
my $min_secs = $min_hour * 3600 + $min_min * 60 + $min_sec; |
357
|
1764021
|
|
|
|
|
1199030
|
my $max_secs = ( $max_hour * 3600 ) + ( $max_min * 60 ) + $max_sec; |
358
|
|
|
|
|
|
|
|
359
|
1764021
|
|
|
|
|
1101269
|
my $delta_secs = $max_secs - $min_secs; |
360
|
|
|
|
|
|
|
|
361
|
1764021
|
50
|
0
|
|
|
1813966
|
cluck('min time is later than max time') && return if $delta_secs < 0; |
362
|
|
|
|
|
|
|
|
363
|
1764021
|
|
|
|
|
1321129
|
$delta_secs = int( rand( $delta_secs + 1 ) ); |
364
|
|
|
|
|
|
|
|
365
|
1764021
|
|
|
|
|
1106414
|
my $result_secs = $min_secs + $delta_secs; |
366
|
|
|
|
|
|
|
|
367
|
1764021
|
|
|
|
|
1126789
|
my $hour = int( $result_secs / 3600 ); |
368
|
1764021
|
|
|
|
|
1205555
|
my $min = int( ( $result_secs - ( $hour * 3600 ) ) / 60 ); |
369
|
1764021
|
|
|
|
|
1060778
|
my $sec = $result_secs % 60; |
370
|
|
|
|
|
|
|
|
371
|
1764021
|
|
|
|
|
3283497
|
return sprintf( "%02u:%02u:%02u", $hour, $min, $sec ); |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
################################################################################ |
375
|
|
|
|
|
|
|
# rand_datetime() |
376
|
|
|
|
|
|
|
################################################################################ |
377
|
|
|
|
|
|
|
sub rand_datetime { |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
# Get the options hash |
380
|
5000
|
|
|
5000
|
1
|
4953779
|
my %options = @_; |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
# Get today's date |
383
|
5000
|
|
|
|
|
9127
|
my $now = localtime; |
384
|
5000
|
|
|
|
|
179425
|
my $minimum; |
385
|
|
|
|
|
|
|
my $maximum; |
386
|
|
|
|
|
|
|
|
387
|
5000
|
100
|
|
|
|
7625
|
if ( $options{min} ) { |
388
|
4000
|
100
|
|
|
|
5835
|
if ( $options{min} eq 'now' ) { |
389
|
1000
|
|
|
|
|
1718
|
$minimum = Time::Piece->strptime( |
390
|
|
|
|
|
|
|
$now->strftime('%Y-%m-%d %H:%M:%S'), |
391
|
|
|
|
|
|
|
'%Y-%m-%d %H:%M:%S' |
392
|
|
|
|
|
|
|
); |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
else { |
395
|
3000
|
|
|
|
|
5786
|
$minimum = Time::Piece->strptime( |
396
|
|
|
|
|
|
|
$options{min}, |
397
|
|
|
|
|
|
|
'%Y-%m-%d %H:%M:%S' |
398
|
|
|
|
|
|
|
); |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
else { |
402
|
1000
|
|
|
|
|
812
|
$minimum = $now; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
5000
|
100
|
|
|
|
74077
|
if ( $options{max} ) { |
406
|
2000
|
100
|
|
|
|
2649
|
if ( $options{max} eq 'now' ) { |
407
|
1000
|
|
|
|
|
1752
|
$maximum = Time::Piece->strptime( |
408
|
|
|
|
|
|
|
$now->strftime('%Y-%m-%d %H:%M:%S'), |
409
|
|
|
|
|
|
|
'%Y-%m-%d %H:%M:%S' |
410
|
|
|
|
|
|
|
); |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
else { |
413
|
1000
|
|
|
|
|
1492
|
$maximum = Time::Piece->strptime( |
414
|
|
|
|
|
|
|
$options{max}, |
415
|
|
|
|
|
|
|
'%Y-%m-%d %H:%M:%S' |
416
|
|
|
|
|
|
|
); |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
else { |
420
|
3000
|
|
|
|
|
5131
|
$maximum = $minimum->add_years(1); |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
5000
|
|
|
|
|
129140
|
my $delta_secs = $maximum - $minimum; |
424
|
5000
|
50
|
0
|
|
|
230712
|
cluck('max_date is later than min date') && return if $delta_secs < 0; |
425
|
5000
|
|
|
|
|
45948
|
$delta_secs = int( rand( $delta_secs + 1 ) ); |
426
|
|
|
|
|
|
|
|
427
|
5000
|
|
|
|
|
55098
|
my $result = $minimum + $delta_secs; |
428
|
|
|
|
|
|
|
|
429
|
5000
|
|
|
|
|
138695
|
return $result->strftime('%Y-%m-%d %H:%M:%S'); |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
################################################################################ |
433
|
|
|
|
|
|
|
# rand_image() |
434
|
|
|
|
|
|
|
################################################################################ |
435
|
|
|
|
|
|
|
sub rand_image { |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
# Get the options hash |
438
|
0
|
|
|
0
|
1
|
0
|
my %options = @_; |
439
|
|
|
|
|
|
|
|
440
|
0
|
|
|
|
|
0
|
eval q{ require GD; }; |
441
|
0
|
0
|
0
|
|
|
0
|
cluck($@) && return if $@; |
442
|
|
|
|
|
|
|
|
443
|
0
|
|
0
|
|
|
0
|
$options{'minwidth'} ||= 1; |
444
|
0
|
|
0
|
|
|
0
|
$options{'maxwidth'} ||= 100; |
445
|
0
|
|
0
|
|
|
0
|
$options{'width'} ||= |
446
|
|
|
|
|
|
|
int( rand( $options{'maxwidth'} - $options{'minwidth'} + 1 ) ) + |
447
|
|
|
|
|
|
|
$options{'minwidth'}; |
448
|
|
|
|
|
|
|
|
449
|
0
|
|
0
|
|
|
0
|
$options{'minheight'} ||= 1; |
450
|
0
|
|
0
|
|
|
0
|
$options{'maxheight'} ||= 100; |
451
|
0
|
|
0
|
|
|
0
|
$options{'height'} ||= |
452
|
|
|
|
|
|
|
int( rand( $options{'maxheight'} - $options{'minheight'} + 1 ) ) + |
453
|
|
|
|
|
|
|
$options{'minheight'}; |
454
|
|
|
|
|
|
|
|
455
|
0
|
|
0
|
|
|
0
|
$options{'minpixels'} ||= 0; |
456
|
0
|
|
0
|
|
|
0
|
$options{'maxpixels'} ||= $options{'width'} * $options{'height'}; |
457
|
0
|
|
0
|
|
|
0
|
$options{'pixels'} ||= |
458
|
|
|
|
|
|
|
int( rand( $options{'maxpixels'} - $options{'minpixels'} + 1 ) ) + |
459
|
|
|
|
|
|
|
$options{'minpixels'}; |
460
|
|
|
|
|
|
|
|
461
|
0
|
|
0
|
|
|
0
|
$options{'bgcolor'} ||= _color(); |
462
|
0
|
|
0
|
|
|
0
|
$options{'fgcolor'} ||= _color(); |
463
|
|
|
|
|
|
|
|
464
|
0
|
|
|
|
|
0
|
my $image = GD::Image->new( $options{'width'}, $options{'height'} ); |
465
|
|
|
|
|
|
|
|
466
|
0
|
|
|
|
|
0
|
my $bgcolor = $image->colorAllocate( @{ $options{'bgcolor'} } ); |
|
0
|
|
|
|
|
0
|
|
467
|
0
|
|
|
|
|
0
|
my $fgcolor = $image->colorAllocate( @{ $options{'fgcolor'} } ); |
|
0
|
|
|
|
|
0
|
|
468
|
|
|
|
|
|
|
|
469
|
0
|
|
|
|
|
0
|
$image->rectangle( 0, 0, $options{'width'}, $options{'height'}, $bgcolor ); |
470
|
|
|
|
|
|
|
|
471
|
0
|
|
|
|
|
0
|
for ( my $i = 0 ; $i < $options{'pixels'} ; $i++ ) { |
472
|
0
|
|
|
|
|
0
|
my $x = int( rand( $options{'width'} + 1 ) ); |
473
|
0
|
|
|
|
|
0
|
my $y = int( rand( $options{'height'} + 1 ) ); |
474
|
|
|
|
|
|
|
|
475
|
0
|
|
|
|
|
0
|
$image->setPixel( $x, $y, $fgcolor ); |
476
|
|
|
|
|
|
|
} |
477
|
|
|
|
|
|
|
|
478
|
0
|
|
|
|
|
0
|
return $image->png(); |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
sub _color { |
481
|
0
|
|
|
0
|
|
0
|
return [ int( rand(256) ), int( rand(256) ), int( rand(256) ) ]; |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
################################################################################ |
486
|
|
|
|
|
|
|
# _shuffle() |
487
|
|
|
|
|
|
|
################################################################################ |
488
|
|
|
|
|
|
|
sub _shuffle { |
489
|
2636
|
|
|
2636
|
|
2137
|
my $array = shift; |
490
|
|
|
|
|
|
|
|
491
|
2636
|
|
|
|
|
4612
|
for ( my $i = @$array - 1 ; $i >= 0 ; $i-- ) { |
492
|
66404
|
|
|
|
|
54475
|
my $j = int( rand( $i + 1 ) ); |
493
|
|
|
|
|
|
|
|
494
|
66404
|
100
|
|
|
|
148412
|
@$array[ $i, $j ] = @$array[ $j, $i ] if $i != $j; |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
1; |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
=head1 NAME |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
Data::Random - Perl module to generate random data |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=head1 SYNOPSIS |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
use Data::Random qw(:all); |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
my @random_words = rand_words( size => 10 ); |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
my @random_chars = rand_chars( set => 'all', min => 5, max => 8 ); |
514
|
|
|
|
|
|
|
my $string = rand_chars( set => 'all', min => 5, max => 8 ); |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
my @random_set = rand_set( set => \@set, size => 5 ); |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
my $random_enum = rand_enum( set => \@set ); |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
my $random_date = rand_date(); |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
my $random_time = rand_time(); |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
my $random_datetime = rand_datetime(); |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
open(my $file, ">", "rand_image.png") or die $!; |
527
|
|
|
|
|
|
|
binmode($file); |
528
|
|
|
|
|
|
|
print $file rand_image( bgcolor => [0, 0, 0] ); |
529
|
|
|
|
|
|
|
close($file); |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=head1 DESCRIPTION |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
A module used to generate random data. Useful mostly for test programs. |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=head1 METHODS |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
=head2 rand_words() |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
This returns a list of random words given a wordlist. See below for possible parameters. |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=over 4 |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
=item * |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
wordlist - the path to the wordlist file. A lot of systems have one at /usr/dict/words. You can also optionally supply a Data::Random::WordList object to keep a persistent wordlist. The default is the wordlist distributed with this module. |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=item * |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
min - the minimum number of words to return. The default is 1. |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=item * |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
max - the maximum number of words to return. The default is 1. |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
=item * |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
size - the number of words to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to. |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
=item * |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
shuffle - whether or not the words should be randomly shuffled. Set this to 0 if you don't want the words shuffled. The default is 1. Random::Data::WordList returns words in the order that they're viewed in the word list file, so shuffling will make sure that the results are a little more random. |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
=back |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=head2 rand_chars() |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
When called in a list context this returns |
571
|
|
|
|
|
|
|
a list of random characters given a set of characters. |
572
|
|
|
|
|
|
|
In a scalar context it returns a string of random characters. |
573
|
|
|
|
|
|
|
See below for possible parameters. |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
=over 4 |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
=item * |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
set - the set of characters to be used. This value can be either a reference to an array of strings, or one of the following: |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
alpha - alphabetic characters: a-z, A-Z |
582
|
|
|
|
|
|
|
upperalpha - upper case alphabetic characters: A-Z |
583
|
|
|
|
|
|
|
loweralpha - lower case alphabetic characters: a-z |
584
|
|
|
|
|
|
|
numeric - numeric characters: 0-9 |
585
|
|
|
|
|
|
|
alphanumeric - alphanumeric characters: a-z, A-Z, 0-9 |
586
|
|
|
|
|
|
|
char - non-alphanumeric characters: # ~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ ` |
587
|
|
|
|
|
|
|
all - all of the above |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=item * |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
min - the minimum number of characters to return. The default is 0. |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=item * |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
max - the maximum number of characters to return. The default is the size of the set. |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
=item * |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
size - the number of characters to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to. |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=item * |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
shuffle - whether or not the characters should be randomly shuffled. Set this to 0 if you want the characters to stay in the order received. The default is 1. |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
=back |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=head2 rand_set() |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
This returns a random set of elements given an initial set. See below for possible parameters. |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
=over 4 |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=item * |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
set - the set of strings to be used. This should be a reference to an array of strings. |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
=item * |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
min - the minimum number of strings to return. The default is 0. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=item * |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
max - the maximum number of strings to return. The default is the size of the set. |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=item * |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
size - the number of strings to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to. |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
=item * |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
shuffle - whether or not the strings should be randomly shuffled. Set this to 0 if you want the strings to stay in the order received. The default is 1. |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=back |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=head2 rand_enum() |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
This returns a random element given an initial set. See below for possible parameters. |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=over 4 |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
=item * |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
set - the set of strings to be used. This should be a reference to an array of strings. |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=back |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
=head2 rand_date() |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
This returns a random date in the form "YYYY-MM-DD". 2-digit years are not currently supported. Efforts are made to make sure you're returned a truly valid date--ie, you'll never be returned the date February 31st. See the options below to find out how to control the date range. Here are a few examples: |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
# returns a date somewhere in between the current date, and one year from the current date |
655
|
|
|
|
|
|
|
$date = rand_date(); |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
# returns a date somewhere in between September 21, 1978 and September 21, 1979 |
658
|
|
|
|
|
|
|
$date = rand_date( min => '1978-9-21' ); |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
# returns a date somewhere in between September 21, 1978 and the current date |
661
|
|
|
|
|
|
|
$date = rand_date( min => '1978-9-21', max => 'now' ); |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
# returns a date somewhere in between the current date and September 21, 2008 |
664
|
|
|
|
|
|
|
$date = rand_date( min => 'now', max => '2008-9-21' ); |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
See below for possible parameters. |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
=over 4 |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
=item * |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
min - the minimum date to be returned. It should be in the form "YYYY-MM-DD" or you can alternatively use the string "now" to represent the current date. The default is the current date; |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
=item * |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
max - the maximum date to be returned. It should be in the form "YYYY-MM-DD" or you can alternatively use the string "now" to represent the current date. The default is one year from the minimum date; |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=back |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=head2 rand_time() |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
This returns a random time in the form "HH:MM:SS". 24 hour times are supported. See the options below to find out how to control the time range. Here are a few examples: |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
# returns a random 24-hr time (between 00:00:00 and 23:59:59) |
686
|
|
|
|
|
|
|
$time = rand_time(); |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
# returns a time somewhere in between 04:00:00 and the end of the day |
689
|
|
|
|
|
|
|
$time = rand_time( min => '4:0:0' ); |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
# returns a time somewhere in between 8:00:00 and the current time (if it's after 8:00) |
692
|
|
|
|
|
|
|
$time = rand_time( min => '12:00:00', max => 'now' ); |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
# returns a date somewhere in between the current time and the end of the day |
695
|
|
|
|
|
|
|
$time = rand_time( min => 'now' ); |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
See below for possible parameters. |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
=over 4 |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=item * |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
min - the minimum time to be returned. It should be in the form "HH:MM:SS" or you can alternatively use the string "now" to represent the current time. The default is 00:00:00; |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
=item * |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
max - the maximum time to be returned. It should be in the form "HH:MM:SS" or you can alternatively use the string "now" to represent the current time. The default is 23:59:59; |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
=back |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=head2 rand_datetime() |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
This returns a random date and time in the form "YYYY-MM-DD HH:MM:SS". See the options below to find out how to control the date/time range. Here are a few examples: |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
# returns a date somewhere in between the current date/time, and one year from the current date/time |
717
|
|
|
|
|
|
|
$datetime = rand_datetime(); |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
# returns a date somewhere in between 4:00 September 21, 1978 and 4:00 September 21, 1979 |
720
|
|
|
|
|
|
|
$datetime = rand_datetime( min => '1978-9-21 4:0:0' ); |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
# returns a date somewhere in between 4:00 September 21, 1978 and the current date |
723
|
|
|
|
|
|
|
$datetime = rand_datetime( min => '1978-9-21 4:0:0', max => 'now' ); |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
# returns a date somewhere in between the current date/time and the end of the day September 21, 2008 |
726
|
|
|
|
|
|
|
$datetime = rand_datetime( min => 'now', max => '2008-9-21 23:59:59' ); |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
See below for possible parameters. |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
=over 4 |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
=item * |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
min - the minimum date/time to be returned. It should be in the form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string "now" to represent the current date/time. The default is the current date/time; |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
=item * |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
max - the maximum date/time to be returned. It should be in the form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string "now" to represent the current date/time. The default is one year from the minimum date/time; |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
=back |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
=head2 rand_image() |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
This returns a random image. Currently only PNG images are supported. See below for possible parameters. |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
=over 4 |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
=item * |
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
minwidth - the minimum width of the image. The default is 1. |
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
=item * |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
maxwidth - the maximum width of the image. The default is 100. |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
=item * |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
width - the width of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to. |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
=item * |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
minheight - the minimum height of the image. The default is 1. |
764
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
=item * |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
maxheight - the maximum height of the image. The default is 100. |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
=item * |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
height - the height of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to. |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
=item * |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
minpixels - the minimum number of random pixels to display on the image. The default is 0. |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
=item * |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
maxpixels - the maximum number of random pixels to display on the image. The default is width * height. |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
=item * |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
pixels - the number of random pixels to display on the image. If you supply a value for 'pixels', then 'minpixels' and 'maxpixels' aren't paid attention to. |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
=item * |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
bgcolor - the background color of the image. The value must be a reference to an RGB array where each element is an integer between 0 and 255 (eg. [ 55, 120, 255 ]). |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
=item * |
790
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
fgcolor - the foreground color of the image. The value must be a reference to an RGB array where each element is an integer between 0 and 255 (eg. [ 55, 120, 255 ]). |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
=back |
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
=head1 VERSION |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
0.11_3 |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
=head1 AUTHOR |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
Originally written by: Adekunle Olonoh |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
Currently maintained by: Buddy Burden (barefoot@cpan.org), starting with version 0.06 |
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
=head1 CREDITS |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
Hiroki Chalfant |
811
|
|
|
|
|
|
|
David Sarno |
812
|
|
|
|
|
|
|
Michiel Beijen |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
=head1 COPYRIGHT |
816
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
Copyright (c) 2000-2011 Adekunle Olonoh. |
818
|
|
|
|
|
|
|
Copyright (c) 2011-2015 Buddy Burden. |
819
|
|
|
|
|
|
|
All rights reserved. This program is free software; you |
820
|
|
|
|
|
|
|
can redistribute it and/or modify it under the same terms as Perl itself. |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
=head1 SEE ALSO |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
L |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
=cut |