File Coverage

blib/lib/Data/Random.pm
Criterion Covered Total %
statement 154 190 81.0
branch 75 98 76.5
condition 26 102 25.4
subroutine 14 16 87.5
pod 8 8 100.0
total 277 414 66.9


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 10     10   1408405 use strict;
  10         25  
  10         422  
13 10     10   108 use warnings;
  10         24  
  10         581  
14 10     10   245 use 5.005_62;
  10         46  
15              
16 10     10   93 use Carp qw(cluck);
  10         58  
  10         770  
17 10     10   8638 use Time::Piece;
  10         195833  
  10         53  
18             #use Data::Random::WordList;
19              
20             require Exporter;
21              
22             ################################################################################
23             # - Global Constants and Variables
24             ################################################################################
25 10         38893 use vars qw(
26             @ISA
27             %EXPORT_TAGS
28             @EXPORT_OK
29             @EXPORT
30 10     10   1371 );
  10         23  
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             our $VERSION = '0.15';
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 176205 my %options = @_;
65              
66             # Initialize max and min vars
67 130   100     346 $options{'min'} ||= 1;
68 130   100     278 $options{'max'} ||= 1;
69              
70             # Initialize the wordlist param
71 130   50     202 $options{'wordlist'} ||= '';
72              
73             # Make sure the max and min vars are OK
74             cluck('min value cannot be larger than max value') && return
75 130 50 0     218 if $options{'min'} > $options{'max'};
76             cluck('min value must be a positive integer') && return
77 130 50 0     382 if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} );
      33        
78             cluck('max value must be a positive integer') && return
79 130 50 0     335 if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} );
      33        
80              
81             # Initialize the size var
82             $options{'size'} ||=
83 130   66     305 int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'};
84              
85             # Make sure the size var is OK
86             cluck('size value must be a positive integer') && return
87 130 50 0     314 if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} );
      33        
88              
89             # Initialize the shuffle flag
90             $options{'shuffle'} =
91 130 100       186 exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1;
92              
93 130         126 my $wl;
94 130         127 my $close_wl = 1;
95              
96             # Check for a pre-existing wordlist object
97 130 50       169 if ( ref( $options{'wordlist'} ) ) {
98 0         0 $wl = $options{'wordlist'};
99 0         0 $close_wl = 0;
100             }
101             else {
102 130         1086 require Data::Random::WordList;
103              
104             # Create a new wordlist object
105 130         292 $wl = Data::Random::WordList->new( wordlist => $options{'wordlist'} );
106             }
107              
108             # Get the random words
109 130         275 my $rand_words = $wl->get_words( $options{'size'} );
110              
111             # Close the word list
112 130 50       296 $wl->close() if $close_wl;
113              
114             # Shuffle the words around
115 130 100       1441 _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       147 if ( wantarray() ) {
119 130         843 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 484480 my %options = @_;
133 3020         4519 my @chars;
134              
135             # Build named character sets if one wasn't supplied
136 3020 100       8222 if ( ref( $options{'set'} ) ne 'ARRAY' ) {
137 302         469 my @charset = ();
138              
139 302 100       1317 if ( $options{'set'} eq 'all' ) {
    100          
    100          
    100          
    100          
    100          
    50          
140 94         1053 @charset =
141             ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z', '#', ',',
142             qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ `),
143             "\\",
144             );
145             }
146             elsif ( $options{'set'} eq 'alpha' ) {
147 52         694 @charset = ( 'a' .. 'z', 'A' .. 'Z' );
148             }
149             elsif ( $options{'set'} eq 'upperalpha' ) {
150 26         107 @charset = ( 'A' .. 'Z' );
151             }
152             elsif ( $options{'set'} eq 'loweralpha' ) {
153 26         207 @charset = ( 'a' .. 'z' );
154             }
155             elsif ( $options{'set'} eq 'numeric' ) {
156 10         34 @charset = ( 0 .. 9 );
157             }
158             elsif ( $options{'set'} eq 'alphanumeric' ) {
159 62         957 @charset = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' );
160             }
161             elsif ( $options{'set'} =~ /^(misc|char)$/ ) {
162 32         223 @charset =
163             ( '#', ',',
164             qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ `),
165             "\\",
166             );
167             }
168              
169 302         617 $options{'set'} = \@charset;
170             }
171              
172 3020         7394 @chars = rand_set(%options);
173 3020 100       25892 return wantarray ? @chars : join('', @chars);
174             }
175              
176             ################################################################################
177             # rand_set()
178             ################################################################################
179             sub rand_set {
180              
181             # Get the options hash
182 3164     3164 1 253129 my %options = @_;
183              
184             # Make sure the set array was defined
185 3164 50 0     6478 cluck('set array is not defined') && return if !$options{'set'};
186              
187             $options{'size'} = 1
188             unless exists( $options{'min'} ) || exists( $options{'max'} )
189 3164 100 66     11105 || exists( $options{'size'} );
      66        
190              
191             # Initialize max and min vars
192 3164   100     9034 $options{'min'} ||= 0;
193 3164   66     6528 $options{'max'} ||= @{ $options{'set'} };
  1898         4445  
194              
195             # Make sure the max and min vars are OK
196             cluck('min value cannot be larger than max value') && return
197 3164 50 0     6589 if $options{'min'} > $options{'max'};
198             cluck('min value must be a positive integer') && return
199 3164 50 0     11305 if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} );
      33        
200             cluck('max value must be a positive integer') && return
201 3164 50 0     10092 if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} );
      33        
202              
203             # Initialize the size var
204             $options{'size'} ||=
205 3164   100     8474 int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'};
206              
207             # Make sure the size var is OK
208             cluck('size value must be a positive integer') && return
209 3164 50 0     10362 if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} );
      33        
210             cluck('size value exceeds set size') && return
211 3164 50 0     4373 if $options{'size'} > @{ $options{'set'} };
  3164         6159  
212              
213             # Initialize the shuffle flag
214             $options{'shuffle'} =
215 3164 100       6428 exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1;
216              
217             # Get the random items
218 3164         4731 my %results = ();
219 3164         7303 for ( my $i = 0 ; $i < $options{'size'} ; $i++ ) {
220 66100         90613 my $result;
221              
222             do {
223 141937         179650 $result = int( rand( @{ $options{'set'} } ) );
  141937         344706  
224 66100         86494 } while ( exists( $results{$result} ) );
225              
226 66100         154698 $results{$result} = 1;
227             }
228              
229 3164         24603 my @results = sort { $a <=> $b } keys %results;
  277167         411729  
230              
231             # Shuffle the items
232 3164 100       15121 _shuffle( \@results ) if $options{'shuffle'};
233              
234             # Return an array or an array reference, depending on the context in which the sub was called
235 3164 50       5644 if ( wantarray() ) {
236 3164         4783 return @{ $options{'set'} }[@results];
  3164         45097  
237             }
238             else {
239 0         0 return \@{ $options{'set'} }[@results];
  0         0  
240             }
241             }
242              
243             ################################################################################
244             # rand_enum()
245             ################################################################################
246             sub rand_enum {
247              
248             # Get the options hash
249 30 100 66 30 1 171082 my %options = @_ == 1 && ref $_[0] eq 'ARRAY' ? ( set => @_ ) : @_;
250              
251             # Make sure the set array was defined
252 30 50 0     51 cluck('set array is not defined') && return if !$options{'set'};
253              
254 30         39 return $options{'set'}->[ int( rand( @{ $options{'set'} } ) ) ];
  30         121  
255             }
256              
257             ################################################################################
258             # rand_date()
259             ################################################################################
260             sub rand_date {
261              
262             # Get the options hash
263 5000     5000 1 14557490 my %options = @_;
264              
265 5000         11973 my $min;
266             my $max;
267             # Get today's date
268 5000         16583 my $t = localtime;
269 5000         344696 my ( $year, $month, $day ) = split('-', $t->ymd);
270 5000         125143 my $today = Time::Piece->strptime($t->ymd, "%Y-%m-%d");
271              
272 5000 100       224962 if ( $options{'min'} ) {
273 4000 100       12828 if ( $options{'min'} eq 'now' ) {
274 1000         1886 $min = $today;
275             }
276             else {
277 3000         9484 $min = Time::Piece->strptime($options{'min'}, '%Y-%m-%d');
278             }
279             }
280             else {
281 1000         1942 $min = $today;
282             }
283 5000 100       75161 if ( $options{'max'} ) {
284 2000 100       4997 if ( $options{'max'} eq 'now' ) {
285 1000         2170 $max = $today;
286             }
287             else {
288 1000         2229 $max = Time::Piece->strptime($options{max}, "%Y-%m-%d");
289             }
290             }
291             else {
292 3000         8465 $max = $min->add_years(1);
293             }
294              
295 5000         200522 my $delta_days = int($max->julian_day) - int($min->julian_day);
296 5000 50 0     355929 cluck('max date is later than min date') && return if $delta_days < 0;
297              
298 5000         23834 my $result = $min + ( 3600 * 24 * int( rand($delta_days + 1) ) );
299 5000         425622 return $result->ymd;
300             }
301              
302             ################################################################################
303             # rand_time()
304             ################################################################################
305             sub rand_time {
306              
307             # Get the options hash
308 1764021     1764021 1 25563990 my %options = @_;
309              
310 1764021         2647018 my ( $min_hour, $min_min, $min_sec, $max_hour, $max_min, $max_sec );
311              
312 1764021 100       3100807 if ( $options{'min'} ) {
313 756011 100       1390537 if ( $options{'min'} eq 'now' ) {
314              
315             # Get the current time
316 1         217 my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ];
317              
318 1         699 ( $min_hour, $min_min, $min_sec ) = ( $hour, $min, $sec );
319             }
320             else {
321 756010         1096070 eval {
322 756010         1848253 my $min = Time::Piece->strptime( $options{min}, '%T' );
323 756010         18738659 ( $min_hour, $min_min, $min_sec )
324             = ( $min->hour, $min->min, $min->sec );
325             };
326 756010 50       8131290 if ($@) {
327 0         0 cluck 'minimum time is not in valid time format HH:MM:SS';
328 0         0 return;
329             }
330             }
331             }
332             else {
333 1008010         1550749 ( $min_hour, $min_min, $min_sec ) = ( 0, 0, 0 );
334             }
335              
336 1764021 100       2921714 if ( $options{'max'} ) {
337 180021 100       328634 if ( $options{'max'} eq 'now' ) {
338              
339             # Get the current time
340 1         22 my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ];
341              
342 1         113 ( $max_hour, $max_min, $max_sec ) = ( $hour, $min, $sec );
343             }
344             else {
345 180020         242290 eval {
346 180020         383134 my $max = Time::Piece->strptime( $options{max}, '%T' );
347 180020         4179154 ( $max_hour, $max_min, $max_sec )
348             = ( $max->hour, $max->min, $max->sec );
349             };
350 180020 50       1849884 if ($@) {
351 0         0 cluck 'maximum time is not in valid time format HH:MM:SS';
352 0         0 return;
353             }
354             }
355             }
356             else {
357 1584000         2433180 ( $max_hour, $max_min, $max_sec ) = ( 23, 59, 59 );
358             }
359              
360 1764021         2636445 my $min_secs = $min_hour * 3600 + $min_min * 60 + $min_sec;
361 1764021         2427637 my $max_secs = ( $max_hour * 3600 ) + ( $max_min * 60 ) + $max_sec;
362              
363 1764021         2391326 my $delta_secs = $max_secs - $min_secs;
364              
365 1764021 50 0     3229994 cluck('min time is later than max time') && return if $delta_secs < 0;
366              
367 1764021         3143404 $delta_secs = int( rand( $delta_secs + 1 ) );
368              
369 1764021         2433300 my $result_secs = $min_secs + $delta_secs;
370              
371 1764021         2635730 my $hour = int( $result_secs / 3600 );
372 1764021         2772521 my $min = int( ( $result_secs - ( $hour * 3600 ) ) / 60 );
373 1764021         2435833 my $sec = $result_secs % 60;
374              
375 1764021         6087583 return sprintf( "%02u:%02u:%02u", $hour, $min, $sec );
376             }
377              
378             ################################################################################
379             # rand_datetime()
380             ################################################################################
381             sub rand_datetime {
382              
383             # Get the options hash
384 5000     5000 1 12156408 my %options = @_;
385              
386             # Get today's date
387 5000         17166 my $now = localtime;
388 5000         340787 my $minimum;
389             my $maximum;
390              
391 5000 100       16333 if ( $options{min} ) {
392 4000 100       10180 if ( $options{min} eq 'now' ) {
393 1000         3785 $minimum = Time::Piece->strptime(
394             $now->strftime('%Y-%m-%d %H:%M:%S'),
395             '%Y-%m-%d %H:%M:%S'
396             );
397             }
398             else {
399             $minimum = Time::Piece->strptime(
400             $options{min},
401 3000         10615 '%Y-%m-%d %H:%M:%S'
402             );
403             }
404             }
405             else {
406 1000         1769 $minimum = $now;
407             }
408              
409 5000 100       178338 if ( $options{max} ) {
410 2000 100       5092 if ( $options{max} eq 'now' ) {
411 1000         3312 $maximum = Time::Piece->strptime(
412             $now->strftime('%Y-%m-%d %H:%M:%S'),
413             '%Y-%m-%d %H:%M:%S'
414             );
415             }
416             else {
417             $maximum = Time::Piece->strptime(
418             $options{max},
419 1000         2241 '%Y-%m-%d %H:%M:%S'
420             );
421             }
422             }
423             else {
424 3000         8954 $maximum = $minimum->add_years(1);
425             }
426              
427 5000         288566 my $delta_secs = $maximum - $minimum;
428 5000 50 0     487751 cluck('max_date is later than min date') && return if $delta_secs < 0;
429 5000         101561 $delta_secs = int( rand( $delta_secs + 1 ) );
430              
431 5000         129646 my $result = $minimum + $delta_secs;
432              
433 5000         228501 return $result->strftime('%Y-%m-%d %H:%M:%S');
434             }
435              
436             ################################################################################
437             # rand_image()
438             ################################################################################
439 0         0 sub rand_image {
440              
441             # Get the options hash
442 0     0 1 0 my %options = @_;
443              
444 0         0 eval q{ require GD; };
445 0 0 0     0 cluck($@) && return if $@;
446              
447 0   0     0 $options{'minwidth'} ||= 1;
448 0   0     0 $options{'maxwidth'} ||= 100;
449             $options{'width'} ||=
450             int( rand( $options{'maxwidth'} - $options{'minwidth'} + 1 ) ) +
451 0   0     0 $options{'minwidth'};
452              
453 0   0     0 $options{'minheight'} ||= 1;
454 0   0     0 $options{'maxheight'} ||= 100;
455             $options{'height'} ||=
456             int( rand( $options{'maxheight'} - $options{'minheight'} + 1 ) ) +
457 0   0     0 $options{'minheight'};
458              
459 0   0     0 $options{'minpixels'} ||= 0;
460 0   0     0 $options{'maxpixels'} ||= $options{'width'} * $options{'height'};
461             $options{'pixels'} ||=
462             int( rand( $options{'maxpixels'} - $options{'minpixels'} + 1 ) ) +
463 0   0     0 $options{'minpixels'};
464              
465 0   0     0 $options{'bgcolor'} ||= _color();
466 0   0     0 $options{'fgcolor'} ||= _color();
467              
468 0         0 my $image = GD::Image->new( $options{'width'}, $options{'height'} );
469              
470 0         0 my $bgcolor = $image->colorAllocate( @{ $options{'bgcolor'} } );
  0         0  
471 0         0 my $fgcolor = $image->colorAllocate( @{ $options{'fgcolor'} } );
  0         0  
472              
473 0         0 $image->rectangle( 0, 0, $options{'width'}, $options{'height'}, $bgcolor );
474              
475 0         0 for ( my $i = 0 ; $i < $options{'pixels'} ; $i++ ) {
476 0         0 my $x = int( rand( $options{'width'} + 1 ) );
477 0         0 my $y = int( rand( $options{'height'} + 1 ) );
478              
479 0         0 $image->setPixel( $x, $y, $fgcolor );
480             }
481              
482 0         0 return $image->png();
483              
484             sub _color {
485 0     0   0 return [ int( rand(256) ), int( rand(256) ), int( rand(256) ) ];
486             }
487             }
488              
489             ################################################################################
490             # _shuffle()
491             ################################################################################
492             sub _shuffle {
493 2636     2636   4058 my $array = shift;
494              
495 2636         5974 for ( my $i = @$array - 1 ; $i >= 0 ; $i-- ) {
496 66081         102876 my $j = int( rand( $i + 1 ) );
497              
498 66081 100       192969 @$array[ $i, $j ] = @$array[ $j, $i ] if $i != $j;
499             }
500             }
501              
502             1;
503              
504              
505              
506             =head1 NAME
507              
508             Data::Random - Perl module to generate random data
509              
510              
511             =head1 SYNOPSIS
512              
513             use Data::Random qw(:all);
514              
515             my @random_words = rand_words( size => 10 );
516              
517             my @random_chars = rand_chars( set => 'all', min => 5, max => 8 );
518             my $string = rand_chars( set => 'all', min => 5, max => 8 );
519              
520             my @random_set = rand_set( set => \@set, size => 5 );
521              
522             my $random_enum = rand_enum( set => \@set );
523             my $random_enum = rand_enum( \@set ); # shortcut
524              
525             my $random_date = rand_date();
526              
527             my $random_time = rand_time();
528              
529             my $random_datetime = rand_datetime();
530              
531             open(my $file, ">", "rand_image.png") or die $!;
532             binmode($file);
533             print $file rand_image( bgcolor => [0, 0, 0] );
534             close($file);
535              
536              
537             =head1 DESCRIPTION
538              
539             A module used to generate random data. Useful mostly for test programs.
540              
541              
542             =head1 METHODS
543              
544             =head2 rand_words()
545              
546             This returns a list of random words given a wordlist. See below for possible parameters.
547              
548             =over 4
549              
550             =item *
551              
552             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.
553              
554             =item *
555              
556             min - the minimum number of words to return. The default is 1.
557              
558             =item *
559              
560             max - the maximum number of words to return. The default is 1.
561              
562             =item *
563              
564             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.
565              
566             =item *
567              
568             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.
569              
570             =back
571              
572              
573             =head2 rand_chars()
574              
575             When called in a list context this returns
576             a list of random characters given a set of characters.
577             In a scalar context it returns a string of random characters.
578             See below for possible parameters.
579              
580             =over 4
581              
582             =item *
583              
584             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:
585              
586             alpha - alphabetic characters: a-z, A-Z
587             upperalpha - upper case alphabetic characters: A-Z
588             loweralpha - lower case alphabetic characters: a-z
589             numeric - numeric characters: 0-9
590             alphanumeric - alphanumeric characters: a-z, A-Z, 0-9
591             char - non-alphanumeric characters: # ~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `
592             misc - same as 'char'
593             all - all of the above
594              
595             =item *
596              
597             min - the minimum number of characters to return. The default is 0.
598              
599             =item *
600              
601             max - the maximum number of characters to return. The default is the size of the set.
602              
603             =item *
604              
605             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.
606              
607             =item *
608              
609             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.
610              
611             =back
612              
613              
614             =head2 rand_set()
615              
616             This returns a random set of elements given an initial set. See below for possible parameters.
617              
618             =over 4
619              
620             =item *
621              
622             set - the set of strings to be used. This should be a reference to an array of strings.
623              
624             =item *
625              
626             min - the minimum number of strings to return. The default is 0.
627              
628             =item *
629              
630             max - the maximum number of strings to return. The default is the size of the set.
631              
632             =item *
633              
634             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.
635              
636             =item *
637              
638             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.
639              
640             =back
641              
642              
643             =head2 rand_enum()
644              
645             This returns a random element given an initial set. See below for possible parameters.
646              
647             =over 4
648              
649             =item *
650              
651             set - the set of strings to be used. This should be a reference to an array of strings. The C key will be assumed if the array reference is passed as the only argument.
652              
653             =back
654              
655              
656             =head2 rand_date()
657              
658             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:
659              
660             # returns a date somewhere in between the current date, and one year from the current date
661             $date = rand_date();
662              
663             # returns a date somewhere in between September 21, 1978 and September 21, 1979
664             $date = rand_date( min => '1978-9-21' );
665              
666             # returns a date somewhere in between September 21, 1978 and the current date
667             $date = rand_date( min => '1978-9-21', max => 'now' );
668              
669             # returns a date somewhere in between the current date and September 21, 2008
670             $date = rand_date( min => 'now', max => '2008-9-21' );
671              
672             See below for possible parameters.
673              
674             =over 4
675              
676             =item *
677              
678             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;
679              
680             =item *
681              
682             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;
683              
684             =back
685              
686              
687             =head2 rand_time()
688              
689             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:
690              
691             # returns a random 24-hr time (between 00:00:00 and 23:59:59)
692             $time = rand_time();
693              
694             # returns a time somewhere in between 04:00:00 and the end of the day
695             $time = rand_time( min => '4:0:0' );
696              
697             # returns a time somewhere in between 8:00:00 and the current time (if it's after 8:00)
698             $time = rand_time( min => '12:00:00', max => 'now' );
699              
700             # returns a date somewhere in between the current time and the end of the day
701             $time = rand_time( min => 'now' );
702              
703             See below for possible parameters.
704              
705             =over 4
706              
707             =item *
708              
709             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;
710              
711             =item *
712              
713             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;
714              
715             =back
716              
717              
718             =head2 rand_datetime()
719              
720             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:
721              
722             # returns a date somewhere in between the current date/time, and one year from the current date/time
723             $datetime = rand_datetime();
724              
725             # returns a date somewhere in between 4:00 September 21, 1978 and 4:00 September 21, 1979
726             $datetime = rand_datetime( min => '1978-9-21 4:0:0' );
727              
728             # returns a date somewhere in between 4:00 September 21, 1978 and the current date
729             $datetime = rand_datetime( min => '1978-9-21 4:0:0', max => 'now' );
730              
731             # returns a date somewhere in between the current date/time and the end of the day September 21, 2008
732             $datetime = rand_datetime( min => 'now', max => '2008-9-21 23:59:59' );
733              
734             See below for possible parameters.
735              
736             =over 4
737              
738             =item *
739              
740             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;
741              
742             =item *
743              
744             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;
745              
746             =back
747              
748              
749             =head2 rand_image()
750              
751             This returns a random image. Currently only PNG images are supported. See below for possible parameters.
752              
753             =over 4
754              
755             =item *
756              
757             minwidth - the minimum width of the image. The default is 1.
758              
759             =item *
760              
761             maxwidth - the maximum width of the image. The default is 100.
762              
763             =item *
764              
765             width - the width of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to.
766              
767             =item *
768              
769             minheight - the minimum height of the image. The default is 1.
770              
771             =item *
772              
773             maxheight - the maximum height of the image. The default is 100.
774              
775             =item *
776              
777             height - the height of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to.
778              
779             =item *
780              
781             minpixels - the minimum number of random pixels to display on the image. The default is 0.
782              
783             =item *
784              
785             maxpixels - the maximum number of random pixels to display on the image. The default is width * height.
786              
787             =item *
788              
789             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.
790              
791             =item *
792              
793             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 ]).
794              
795             =item *
796              
797             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 ]).
798              
799             =back
800              
801              
802             =head1 VERSION
803              
804             0.12
805              
806              
807             =head1 AUTHOR
808              
809             Originally written by: Adekunle Olonoh
810              
811             Currently maintained by: Buddy Burden (barefoot@cpan.org), starting with version 0.06
812              
813              
814             =head1 CREDITS
815              
816             Hiroki Chalfant
817             David Sarno
818             Michiel Beijen
819              
820              
821             =head1 COPYRIGHT
822              
823             Copyright (c) 2000-2011 Adekunle Olonoh.
824             Copyright (c) 2011-2015 Buddy Burden.
825             All rights reserved. This program is free software; you
826             can redistribute it and/or modify it under the same terms as Perl itself.
827              
828              
829             =head1 SEE ALSO
830              
831             L
832              
833             =cut