Random.pm

filter: Statementstmt 82.2% 162 / 197 Branchbran 76.4% 81 / 106 Conditioncond 27.2% 40 / 147 MC/DCmcdc 8.8% 6 / 68 Subroutinesub 87.5% 14 / 16 Podpod 100% 8 / 8 totaltotal 57.3% 311 / 542 CC 96 SCAR 41.5
CC
96
Cov
63%
rand_image
240.0
rand_set
72.3
rand_words
56.2
CRAP 63.7
↑ Summary Random/WordList.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use 5.005_62;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 ▶use Carp qw(cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 #use Data::Random::WordList;
19  
20 10 require Exporter;
21  
22 ################################################################################
23 # - Global Constants and Variables
24 ################################################################################
25 10 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 @ISA
27 %EXPORT_TAGS
28 @EXPORT_OK
29 @EXPORT
30 10 );
31  
32 10 @ISA = qw(Exporter);
33  
34 10 %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 10 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
50 10 @EXPORT = qw();
51  
52 10 our $VERSION = '0.15';
53  
54 ################################################################################
55 # - Subroutines
56 ################################################################################
57  
58 ################################################################################
59 # rand_words()
60 ################################################################################
61 130 ▶sub rand_words {
Subroutine rand_words: called CC=21 SCAR=40.3
Pod documented
62  
63 # Get the options hash
64 130 my %options = @_;
65  
66 # Initialize max and min vars
67 130 ▶ $options{'min'} ||= 1;
Condition100%2/2
$options{"min"} ||= 1
l!l
5080
MC/DC100%1/1
$options{"min"} ||= 1
$options{"min"}
Truth table100%2/2
A
A= $options{"min"}
Aresult
11
00
68 130 ▶ $options{'max'} ||= 1;
Condition100%2/2
$options{"max"} ||= 1
l!l
5278
MC/DC100%1/1
$options{"max"} ||= 1
$options{"max"}
Truth table100%2/2
A
A= $options{"max"}
Aresult
11
00
69  
70 # Initialize the wordlist param
71 130 ▶ $options{'wordlist'} ||= '';
Condition50%1/2
$options{"wordlist"} ||= ""
l!l
1300
MC/DC0%0/1
$options{"wordlist"} ||= ""
$options{"wordlist"}
Truth table50%1/2
A
A= $options{"wordlist"}
Aresult
11
00
72  
73 # Make sure the max and min vars are OK
74 cluck('min value cannot be larger than max value') && return
75 130 ▶ if $options{'min'} > $options{'max'};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"min"} > $options{"max"} 0 130 130
Condition20%1/5
$options{'min'} > $options{'max'} && (cluck('min value cannot be larger than max value') && (return))
!ll&&!rl&&r
13000
cluck("min value cannot be larger than max value") and return
!ll
00
MC/DC0%0/2
$options{'min'} > $options{'max'} && (cluck('min value cannot be larger than max value') && (return))
$options{'min'} > $options{'max'} cluck("min value cannot be larger than max value")
Truth table33%1/3
A && B
A= $options{'min'} > $options{'max'}B= cluck("min value cannot be larger than max value")
ABresult
0X0
100
111
76 cluck('min value must be a positive integer') && return
77 130 ▶ if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} );
Branch: 1 branch
BranchTrueFalseTotal
if $options{"min"} < 0 or $options{"min"} != int $options{"min"} 0 130 130
Condition25%2/8
($options{'min'} < 0 || $options{'min'} != int $options{'min'}) && (cluck('min value must be a positive integer') && (return))
!ll&&!rl&&r
13000
$options{"min"} < 0 or $options{"min"} != int $options{"min"}
l!l&&r!l&&!r
00130
cluck("min value must be a positive integer") and return
!ll
00
MC/DC0%0/3
($options{'min'} < 0 || $options{'min'} != int $options{'min'}) && (cluck('min value must be a positive integer') && (return))
$options{"min"} < 0 $options{"min"} != int $options{"min"} cluck("min value must be a positive integer")
Truth table20%1/5
A or B && C
A= $options{"min"} < 0B= $options{"min"} != int $options{"min"}C= cluck("min value must be a positive integer")
ABCresult
00X0
1X00
0100
1X11
0111
78 cluck('max value must be a positive integer') && return
79 130 ▶ if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} );
Branch: 1 branch
BranchTrueFalseTotal
if $options{"max"} < 0 or $options{"max"} != int $options{"max"} 0 130 130
Condition25%2/8
($options{'max'} < 0 || $options{'max'} != int $options{'max'}) && (cluck('max value must be a positive integer') && (return))
!ll&&!rl&&r
13000
$options{"max"} < 0 or $options{"max"} != int $options{"max"}
l!l&&r!l&&!r
00130
cluck("max value must be a positive integer") and return
!ll
00
MC/DC0%0/3
($options{'max'} < 0 || $options{'max'} != int $options{'max'}) && (cluck('max value must be a positive integer') && (return))
$options{"max"} < 0 $options{"max"} != int $options{"max"} cluck("max value must be a positive integer")
Truth table20%1/5
A or B && C
A= $options{"max"} < 0B= $options{"max"} != int $options{"max"}C= cluck("max value must be a positive integer")
ABCresult
00X0
1X00
0100
1X11
0111
80  
81 # Initialize the size var
82 $options{'size'} ||=
83 130 ▶ int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'};
Condition66%2/3
$options{"size"} ||= int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
l!l&&r!l&&!r
78520
MC/DC0%0/2
$options{"size"} ||= int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
$options{"size"} int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
Truth table66%2/3
A ||= B
A= $options{"size"}B= int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
ABresult
1X1
011
000
84  
85 # Make sure the size var is OK
86 cluck('size value must be a positive integer') && return
87 130 ▶ if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} );
Branch: 1 branch
BranchTrueFalseTotal
if $options{"size"} < 0 or $options{"size"} != int $options{"size"} 0 130 130
Condition25%2/8
($options{'size'} < 0 || $options{'size'} != int $options{'size'}) && (cluck('size value must be a positive integer') && (return))
!ll&&!rl&&r
13000
$options{"size"} < 0 or $options{"size"} != int $options{"size"}
l!l&&r!l&&!r
00130
cluck("size value must be a positive integer") and return
!ll
00
MC/DC0%0/3
($options{'size'} < 0 || $options{'size'} != int $options{'size'}) && (cluck('size value must be a positive integer') && (return))
$options{"size"} < 0 $options{"size"} != int $options{"size"} cluck("size value must be a positive integer")
Truth table20%1/5
A or B && C
A= $options{"size"} < 0B= $options{"size"} != int $options{"size"}C= cluck("size value must be a positive integer")
ABCresult
00X0
1X00
0100
1X11
0111
88  
89 # Initialize the shuffle flag
90 $options{'shuffle'} =
91 130 ▶ exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'shuffle'} ? : 26 104 130
92  
93 130 my $wl;
94 130 my $close_wl = 1;
95  
96 # Check for a pre-existing wordlist object
97 130 ▶ if ( ref( $options{'wordlist'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options{'wordlist'}) { } 0 130 130
98 0 $wl = $options{'wordlist'};
99 0 $close_wl = 0;
100 }
101 else {
102 130 require Data::Random::WordList;
103  
104 # Create a new wordlist object
105 130 $wl = Data::Random::WordList->new( wordlist => $options{'wordlist'} );
106 }
107  
108 # Get the random words
109 130 my $rand_words = $wl->get_words( $options{'size'} );
110  
111 # Close the word list
112 130 ▶ $wl->close() if $close_wl;
Branch: 1 branch
BranchTrueFalseTotal
if $close_wl 130 0 130
113  
114 # Shuffle the words around
115 130 ▶ _shuffle($rand_words) if $options{'shuffle'};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"shuffle"} 104 26 130
116  
117 # Return an array or an array reference, depending on the context in which the sub was called
118 130 ▶ if ( wantarray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 130 0 130
119 130 return @$rand_words;
120 }
121 else {
122 0 return $rand_words;
123 }
124 }
125  
126 ################################################################################
127 # rand_chars()
128 ################################################################################
129 3020 ▶sub rand_chars {
Subroutine rand_chars: called CC=10 SCAR=23.0
Pod documented
130  
131 # Get the options hash
132 3020 my %options = @_;
133 3020 my @chars;
134  
135 # Build named character sets if one wasn't supplied
136 3020 ▶ if ( ref( $options{'set'} ) ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options{"set"} ne "ARRAY") 302 2718 3020
137 302 my @charset = ();
138  
139 302 ▶ if ( $options{'set'} eq 'all' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($options{'set'} eq 'all') { } 94 208 302
elsif ($options{'set'} eq 'alpha') { } 52 156 208
elsif ($options{'set'} eq 'upperalpha') { } 26 130 156
elsif ($options{'set'} eq 'loweralpha') { } 26 104 130
elsif ($options{'set'} eq 'numeric') { } 10 94 104
elsif ($options{'set'} eq 'alphanumeric') { } 62 32 94
elsif ($options{'set'} =~ /^(misc|char)$/) { } 32 0 32
140 94 @charset =
141 ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z', '#', ',',
142 qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ `),
143 "\\",
144 );
145 }
146 elsif ( $options{'set'} eq 'alpha' ) {
147 52 @charset = ( 'a' .. 'z', 'A' .. 'Z' );
148 }
149 elsif ( $options{'set'} eq 'upperalpha' ) {
150 26 @charset = ( 'A' .. 'Z' );
151 }
152 elsif ( $options{'set'} eq 'loweralpha' ) {
153 26 @charset = ( 'a' .. 'z' );
154 }
155 elsif ( $options{'set'} eq 'numeric' ) {
156 10 @charset = ( 0 .. 9 );
157 }
158 elsif ( $options{'set'} eq 'alphanumeric' ) {
159 62 @charset = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' );
160 }
161 elsif ( $options{'set'} =~ /^(misc|char)$/ ) {
162 32 @charset =
163 ( '#', ',',
164 qw(~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ `),
165 "\\",
166 );
167 }
168  
169 302 $options{'set'} = \@charset;
170 }
171  
172 3020 @chars = rand_set(%options);
173 3020 ▶ return wantarray ? @chars : join('', @chars);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1510 1510 3020
174 }
175  
176 ################################################################################
177 # rand_set()
178 ################################################################################
179 3164 ▶sub rand_set {
Subroutine rand_set: called CC=27 SCAR=42.8
Pod documented
180  
181 # Get the options hash
182 3164 my %options = @_;
183  
184 # Make sure the set array was defined
185 3164 ▶ cluck('set array is not defined') && return if !$options{'set'};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"set"} 0 3164 3164
Condition20%1/5
$options{'set'} || cluck('set array is not defined') && (return)
l!l&&r!l&&!r
316400
cluck("set array is not defined") and return
!ll
00
MC/DC0%0/2
$options{'set'} || cluck('set array is not defined') && (return)
$options{'set'} cluck("set array is not defined")
Truth table33%1/3
A || B
A= $options{'set'}B= cluck("set array is not defined")
ABresult
1X1
011
000
186  
187 $options{'size'} = 1
188 unless exists( $options{'min'} ) || exists( $options{'max'} )
189 3164 ▶ || exists( $options{'size'} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options{"min"} or exists $options{"max"} or exists $options{"size"} 633 2531 3164
Condition83%5/6
exists $options{"min"} or exists $options{"max"} or exists $options{"size"}
l!l&&r!l&&!r
12661265633
exists $options{"min"} or exists $options{"max"}
l!l&&r!l&&!r
126601898
MC/DC66%2/3
exists $options{"min"} or exists $options{"max"} or exists $options{"size"}
exists $options{"min"} exists $options{"max"} exists $options{"size"}
Truth table75%3/4
A or B or C
A= exists $options{"min"}B= exists $options{"max"}C= exists $options{"size"}
ABCresult
1XX1
01X1
0011
0000
190  
191 # Initialize max and min vars
192 3164 ▶ $options{'min'} ||= 0;
Condition100%2/2
$options{"min"} ||= 0
l!l
12321932
MC/DC100%1/1
$options{"min"} ||= 0
$options{"min"}
Truth table100%2/2
A
A= $options{"min"}
Aresult
11
00
193 3164 ▶ $options{'max'} ||= @{ $options{'set'} };
Condition66%2/3
$options{"max"} ||= @{$options{"set"};}
l!l&&r!l&&!r
126618980
MC/DC0%0/2
$options{"max"} ||= @{$options{"set"};}
$options{"max"} @{$options{"set"};}
Truth table66%2/3
A ||= B
A= $options{"max"}B= @{$options{"set"};}
ABresult
1X1
011
000
194  
195 # Make sure the max and min vars are OK
196 cluck('min value cannot be larger than max value') && return
197 3164 ▶ if $options{'min'} > $options{'max'};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"min"} > $options{"max"} 0 3164 3164
Condition20%1/5
$options{'min'} > $options{'max'} && (cluck('min value cannot be larger than max value') && (return))
!ll&&!rl&&r
316400
cluck("min value cannot be larger than max value") and return
!ll
00
MC/DC0%0/2
$options{'min'} > $options{'max'} && (cluck('min value cannot be larger than max value') && (return))
$options{'min'} > $options{'max'} cluck("min value cannot be larger than max value")
Truth table33%1/3
A && B
A= $options{'min'} > $options{'max'}B= cluck("min value cannot be larger than max value")
ABresult
0X0
100
111
198 cluck('min value must be a positive integer') && return
199 3164 ▶ if $options{'min'} < 0 || $options{'min'} != int( $options{'min'} );
Branch: 1 branch
BranchTrueFalseTotal
if $options{"min"} < 0 or $options{"min"} != int $options{"min"} 0 3164 3164
Condition25%2/8
($options{'min'} < 0 || $options{'min'} != int $options{'min'}) && (cluck('min value must be a positive integer') && (return))
!ll&&!rl&&r
316400
$options{"min"} < 0 or $options{"min"} != int $options{"min"}
l!l&&r!l&&!r
003164
cluck("min value must be a positive integer") and return
!ll
00
MC/DC0%0/3
($options{'min'} < 0 || $options{'min'} != int $options{'min'}) && (cluck('min value must be a positive integer') && (return))
$options{"min"} < 0 $options{"min"} != int $options{"min"} cluck("min value must be a positive integer")
Truth table20%1/5
A or B && C
A= $options{"min"} < 0B= $options{"min"} != int $options{"min"}C= cluck("min value must be a positive integer")
ABCresult
00X0
1X00
0100
1X11
0111
200 cluck('max value must be a positive integer') && return
201 3164 ▶ if $options{'max'} < 0 || $options{'max'} != int( $options{'max'} );
Branch: 1 branch
BranchTrueFalseTotal
if $options{"max"} < 0 or $options{"max"} != int $options{"max"} 0 3164 3164
Condition25%2/8
($options{'max'} < 0 || $options{'max'} != int $options{'max'}) && (cluck('max value must be a positive integer') && (return))
!ll&&!rl&&r
316400
$options{"max"} < 0 or $options{"max"} != int $options{"max"}
l!l&&r!l&&!r
003164
cluck("max value must be a positive integer") and return
!ll
00
MC/DC0%0/3
($options{'max'} < 0 || $options{'max'} != int $options{'max'}) && (cluck('max value must be a positive integer') && (return))
$options{"max"} < 0 $options{"max"} != int $options{"max"} cluck("max value must be a positive integer")
Truth table20%1/5
A or B && C
A= $options{"max"} < 0B= $options{"max"} != int $options{"max"}C= cluck("max value must be a positive integer")
ABCresult
00X0
1X00
0100
1X11
0111
202  
203 # Initialize the size var
204 $options{'size'} ||=
205 3164 ▶ int( rand( $options{'max'} - $options{'min'} + 1 ) ) + $options{'min'};
Condition66%2/3
$options{"size"} ||= int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
l!l&&r!l&&!r
25316330
MC/DC0%0/2
$options{"size"} ||= int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
$options{"size"} int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
Truth table66%2/3
A ||= B
A= $options{"size"}B= int(rand $options{"max"} - $options{"min"} + 1) + $options{"min"}
ABresult
1X1
011
000
206  
207 # Make sure the size var is OK
208 cluck('size value must be a positive integer') && return
209 3164 ▶ if $options{'size'} < 0 || $options{'size'} != int( $options{'size'} );
Branch: 1 branch
BranchTrueFalseTotal
if $options{"size"} < 0 or $options{"size"} != int $options{"size"} 0 3164 3164
Condition25%2/8
($options{'size'} < 0 || $options{'size'} != int $options{'size'}) && (cluck('size value must be a positive integer') && (return))
!ll&&!rl&&r
316400
$options{"size"} < 0 or $options{"size"} != int $options{"size"}
l!l&&r!l&&!r
003164
cluck("size value must be a positive integer") and return
!ll
00
MC/DC0%0/3
($options{'size'} < 0 || $options{'size'} != int $options{'size'}) && (cluck('size value must be a positive integer') && (return))
$options{"size"} < 0 $options{"size"} != int $options{"size"} cluck("size value must be a positive integer")
Truth table20%1/5
A or B && C
A= $options{"size"} < 0B= $options{"size"} != int $options{"size"}C= cluck("size value must be a positive integer")
ABCresult
00X0
1X00
0100
1X11
0111
210 cluck('size value exceeds set size') && return
211 3164 ▶ if $options{'size'} > @{ $options{'set'} };
Branch: 1 branch
BranchTrueFalseTotal
if $options{"size"} > @{$options{"set"};} 0 3164 3164
Condition20%1/5
$options{'size'} > @{$options{'set'};} && (cluck('size value exceeds set size') && (return))
!ll&&!rl&&r
316400
cluck("size value exceeds set size") and return
!ll
00
MC/DC0%0/2
$options{'size'} > @{$options{'set'};} && (cluck('size value exceeds set size') && (return))
$options{'size'} > @{$options{'set'};} cluck("size value exceeds set size")
Truth table33%1/3
A && B
A= $options{'size'} > @{$options{'set'};}B= cluck("size value exceeds set size")
ABresult
0X0
100
111
212  
213 # Initialize the shuffle flag
214 $options{'shuffle'} =
215 3164 ▶ exists( $options{'shuffle'} ) ? $options{'shuffle'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'shuffle'} ? : 632 2532 3164
216  
217 # Get the random items
218 3164 my %results = ();
219 3164 ▶ for ( my $i = 0 ; $i < $options{'size'} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $options{"size"}) 66135 3164 69299
220 66135 my $result;
221  
222 do {
223 142475 $result = int( rand( @{ $options{'set'} } ) );
224 66135 ▶ } while ( exists( $results{$result} ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $results{$result} and do { do { $result = int rand @{$options{"set"};} } } 76340 66135 142475
225  
226 66135 $results{$result} = 1;
227 }
228  
229 3164 my @results = sort { $a <=> $b } keys %results;
230  
231 # Shuffle the items
232 3164 ▶ _shuffle( \@results ) if $options{'shuffle'};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"shuffle"} 2532 632 3164
233  
234 # Return an array or an array reference, depending on the context in which the sub was called
235 3164 ▶ if ( wantarray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 3164 0 3164
236 3164 return @{ $options{'set'} }[@results];
237 }
238 else {
239 0 return \@{ $options{'set'} }[@results];
240 }
241 }
242  
243 ################################################################################
244 # rand_enum()
245 ################################################################################
246 30 ▶sub rand_enum {
Subroutine rand_enum: called CC=5 SCAR=18.4
Pod documented
247  
248 # Get the options hash
249 30 ▶ my %options = @_ == 1 && ref $_[0] eq 'ARRAY' ? ( set => @_ ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 1 29 30
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
2901
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
250  
251 # Make sure the set array was defined
252 30 ▶ cluck('set array is not defined') && return if !$options{'set'};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"set"} 0 30 30
Condition20%1/5
$options{'set'} || cluck('set array is not defined') && (return)
l!l&&r!l&&!r
3000
cluck("set array is not defined") and return
!ll
00
MC/DC0%0/2
$options{'set'} || cluck('set array is not defined') && (return)
$options{'set'} cluck("set array is not defined")
Truth table33%1/3
A || B
A= $options{'set'}B= cluck("set array is not defined")
ABresult
1X1
011
000
253  
254 30 return $options{'set'}->[ int( rand( @{ $options{'set'} } ) ) ];
255 }
256  
257 ################################################################################
258 # rand_date()
259 ################################################################################
260 5000 ▶sub rand_date {
Subroutine rand_date: called CC=7 SCAR=19.7
Pod documented
261  
262 # Get the options hash
263 5000 my %options = @_;
264  
265 5000 my $min;
266 my $max;
267 # Get today's date
268 5000 my $t = localtime;
269 5000 my ( $year, $month, $day ) = split('-', $t->ymd);
270 5000 my $today = Time::Piece->strptime($t->ymd, "%Y-%m-%d");
271  
272 5000 ▶ if ( $options{'min'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'min'}) { } 4000 1000 5000
273 4000 ▶ if ( $options{'min'} eq 'now' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'min'} eq 'now') { } 1000 3000 4000
274 1000 $min = $today;
275 }
276 else {
277 3000 $min = Time::Piece->strptime($options{'min'}, '%Y-%m-%d');
278 }
279 }
280 else {
281 1000 $min = $today;
282 }
283 5000 ▶ if ( $options{'max'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'max'}) { } 2000 3000 5000
284 2000 ▶ if ( $options{'max'} eq 'now' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'max'} eq 'now') { } 1000 1000 2000
285 1000 $max = $today;
286 }
287 else {
288 1000 $max = Time::Piece->strptime($options{max}, "%Y-%m-%d");
289 }
290 }
291 else {
292 3000 $max = $min->add_years(1);
293 }
294  
295 5000 my $delta_days = int($max->julian_day) - int($min->julian_day);
296 5000 ▶ cluck('max date is later than min date') && return if $delta_days < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $delta_days < 0 0 5000 5000
Condition20%1/5
$delta_days < 0 && (cluck('max date is later than min date') && (return))
!ll&&!rl&&r
500000
cluck("max date is later than min date") and return
!ll
00
MC/DC0%0/2
$delta_days < 0 && (cluck('max date is later than min date') && (return))
$delta_days < 0 cluck("max date is later than min date")
Truth table33%1/3
A && B
A= $delta_days < 0B= cluck("max date is later than min date")
ABresult
0X0
100
111
297  
298 5000 my $result = $min + ( 3600 * 24 * int( rand($delta_days + 1) ) );
299 5000 return $result->ymd;
300 }
301  
302 ################################################################################
303 # rand_time()
304 ################################################################################
305 1764021 ▶sub rand_time {
Subroutine rand_time: called CC=9 SCAR=22.7
Pod documented
306  
307 # Get the options hash
308 1764021 my %options = @_;
309  
310 1764021 my ( $min_hour, $min_min, $min_sec, $max_hour, $max_min, $max_sec );
311  
312 1764021 ▶ if ( $options{'min'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'min'}) { } 756011 1008010 1764021
313 756011 ▶ if ( $options{'min'} eq 'now' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'min'} eq 'now') { } 1 756010 756011
314  
315 # Get the current time
316 1 my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ];
317  
318 1 ( $min_hour, $min_min, $min_sec ) = ( $hour, $min, $sec );
319 }
320 else {
321 756010 eval {
322 756010 my $min = Time::Piece->strptime( $options{min}, '%T' );
323 756010 ( $min_hour, $min_min, $min_sec )
324 = ( $min->hour, $min->min, $min->sec );
325 };
326 756010 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 756010 756010
327 0 cluck 'minimum time is not in valid time format HH:MM:SS';
328 0 return;
329 }
330 }
331 }
332 else {
333 1008010 ( $min_hour, $min_min, $min_sec ) = ( 0, 0, 0 );
334 }
335  
336 1764021 ▶ if ( $options{'max'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'max'}) { } 180021 1584000 1764021
337 180021 ▶ if ( $options{'max'} eq 'now' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'max'} eq 'now') { } 1 180020 180021
338  
339 # Get the current time
340 1 my ( $hour, $min, $sec ) = ( localtime() )[ 2, 1, 0 ];
341  
342 1 ( $max_hour, $max_min, $max_sec ) = ( $hour, $min, $sec );
343 }
344 else {
345 180020 eval {
346 180020 my $max = Time::Piece->strptime( $options{max}, '%T' );
347 180020 ( $max_hour, $max_min, $max_sec )
348 = ( $max->hour, $max->min, $max->sec );
349 };
350 180020 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 180020 180020
351 0 cluck 'maximum time is not in valid time format HH:MM:SS';
352 0 return;
353 }
354 }
355 }
356 else {
357 1584000 ( $max_hour, $max_min, $max_sec ) = ( 23, 59, 59 );
358 }
359  
360 1764021 my $min_secs = $min_hour * 3600 + $min_min * 60 + $min_sec;
361 1764021 my $max_secs = ( $max_hour * 3600 ) + ( $max_min * 60 ) + $max_sec;
362  
363 1764021 my $delta_secs = $max_secs - $min_secs;
364  
365 1764021 ▶ cluck('min time is later than max time') && return if $delta_secs < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $delta_secs < 0 0 1764021 1764021
Condition20%1/5
$delta_secs < 0 && (cluck('min time is later than max time') && (return))
!ll&&!rl&&r
176402100
cluck("min time is later than max time") and return
!ll
00
MC/DC0%0/2
$delta_secs < 0 && (cluck('min time is later than max time') && (return))
$delta_secs < 0 cluck("min time is later than max time")
Truth table33%1/3
A && B
A= $delta_secs < 0B= cluck("min time is later than max time")
ABresult
0X0
100
111
366  
367 1764021 $delta_secs = int( rand( $delta_secs + 1 ) );
368  
369 1764021 my $result_secs = $min_secs + $delta_secs;
370  
371 1764021 my $hour = int( $result_secs / 3600 );
372 1764021 my $min = int( ( $result_secs - ( $hour * 3600 ) ) / 60 );
373 1764021 my $sec = $result_secs % 60;
374  
375 1764021 return sprintf( "%02u:%02u:%02u", $hour, $min, $sec );
376 }
377  
378 ################################################################################
379 # rand_datetime()
380 ################################################################################
381 5000 ▶sub rand_datetime {
Subroutine rand_datetime: called CC=7 SCAR=19.7
Pod documented
382  
383 # Get the options hash
384 5000 my %options = @_;
385  
386 # Get today's date
387 5000 my $now = localtime;
388 5000 my $minimum;
389 my $maximum;
390  
391 5000 ▶ if ( $options{min} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'min'}) { } 4000 1000 5000
392 4000 ▶ if ( $options{min} eq 'now' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'min'} eq 'now') { } 1000 3000 4000
393 1000 $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 '%Y-%m-%d %H:%M:%S'
402 );
403 }
404 }
405 else {
406 1000 $minimum = $now;
407 }
408  
409 5000 ▶ if ( $options{max} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'max'}) { } 2000 3000 5000
410 2000 ▶ if ( $options{max} eq 'now' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'max'} eq 'now') { } 1000 1000 2000
411 1000 $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 '%Y-%m-%d %H:%M:%S'
420 );
421 }
422 }
423 else {
424 3000 $maximum = $minimum->add_years(1);
425 }
426  
427 5000 my $delta_secs = $maximum - $minimum;
428 5000 ▶ cluck('max_date is later than min date') && return if $delta_secs < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $delta_secs < 0 0 5000 5000
Condition20%1/5
$delta_secs < 0 && (cluck('max_date is later than min date') && (return))
!ll&&!rl&&r
500000
cluck("max_date is later than min date") and return
!ll
00
MC/DC0%0/2
$delta_secs < 0 && (cluck('max_date is later than min date') && (return))
$delta_secs < 0 cluck("max_date is later than min date")
Truth table33%1/3
A && B
A= $delta_secs < 0B= cluck("max_date is later than min date")
ABresult
0X0
100
111
429 5000 $delta_secs = int( rand( $delta_secs + 1 ) );
430  
431 5000 my $result = $minimum + $delta_secs;
432  
433 5000 return $result->strftime('%Y-%m-%d %H:%M:%S');
434 }
435  
436 ################################################################################
437 # rand_image()
438 ################################################################################
439 0 ▶sub rand_image {
Subroutine rand_image: not called CC=15 SCAR=54.8
Pod documented
440  
441 # Get the options hash
442 0 my %options = @_;
443  
444 0 eval q{ require GD; };
445 0 ▶ cluck($@) && return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
Condition0%0/5
$@ && (cluck($@) && (return))
!ll&&!rl&&r
000
cluck($@) and return
!ll
00
MC/DC0%0/2
$@ && (cluck($@) && (return))
$@ cluck($@)
Truth table0%0/3
A && B
A= $@B= cluck($@)
ABresult
0X0
100
111
446  
447 0 ▶ $options{'minwidth'} ||= 1;
Condition0%0/2
$options{"minwidth"} ||= 1
l!l
00
MC/DC0%0/1
$options{"minwidth"} ||= 1
$options{"minwidth"}
Truth table0%0/2
A
A= $options{"minwidth"}
Aresult
11
00
448 0 ▶ $options{'maxwidth'} ||= 100;
Condition0%0/2
$options{"maxwidth"} ||= 100
l!l
00
MC/DC0%0/1
$options{"maxwidth"} ||= 100
$options{"maxwidth"}
Truth table0%0/2
A
A= $options{"maxwidth"}
Aresult
11
00
449 $options{'width'} ||=
450 int( rand( $options{'maxwidth'} - $options{'minwidth'} + 1 ) ) +
451 0 ▶ $options{'minwidth'};
Condition0%0/3
$options{"width"} ||= int(rand $options{"maxwidth"} - $options{"minwidth"} + 1) + $options{"minwidth"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"width"} ||= int(rand $options{"maxwidth"} - $options{"minwidth"} + 1) + $options{"minwidth"}
$options{"width"} int(rand $options{"maxwidth"} - $options{"minwidth"} + 1) + $options{"minwidth"}
Truth table0%0/3
A ||= B
A= $options{"width"}B= int(rand $options{"maxwidth"} - $options{"minwidth"} + 1) + $options{"minwidth"}
ABresult
1X1
011
000
452  
453 0 ▶ $options{'minheight'} ||= 1;
Condition0%0/2
$options{"minheight"} ||= 1
l!l
00
MC/DC0%0/1
$options{"minheight"} ||= 1
$options{"minheight"}
Truth table0%0/2
A
A= $options{"minheight"}
Aresult
11
00
454 0 ▶ $options{'maxheight'} ||= 100;
Condition0%0/2
$options{"maxheight"} ||= 100
l!l
00
MC/DC0%0/1
$options{"maxheight"} ||= 100
$options{"maxheight"}
Truth table0%0/2
A
A= $options{"maxheight"}
Aresult
11
00
455 $options{'height'} ||=
456 int( rand( $options{'maxheight'} - $options{'minheight'} + 1 ) ) +
457 0 ▶ $options{'minheight'};
Condition0%0/3
$options{"height"} ||= int(rand $options{"maxheight"} - $options{"minheight"} + 1) + $options{"minheight"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"height"} ||= int(rand $options{"maxheight"} - $options{"minheight"} + 1) + $options{"minheight"}
$options{"height"} int(rand $options{"maxheight"} - $options{"minheight"} + 1) + $options{"minheight"}
Truth table0%0/3
A ||= B
A= $options{"height"}B= int(rand $options{"maxheight"} - $options{"minheight"} + 1) + $options{"minheight"}
ABresult
1X1
011
000
458  
459 0 ▶ $options{'minpixels'} ||= 0;
Condition0%0/2
$options{"minpixels"} ||= 0
l!l
00
MC/DC0%0/1
$options{"minpixels"} ||= 0
$options{"minpixels"}
Truth table0%0/2
A
A= $options{"minpixels"}
Aresult
11
00
460 0 ▶ $options{'maxpixels'} ||= $options{'width'} * $options{'height'};
Condition0%0/3
$options{"maxpixels"} ||= $options{"width"} * $options{"height"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"maxpixels"} ||= $options{"width"} * $options{"height"}
$options{"maxpixels"} $options{"width"} * $options{"height"}
Truth table0%0/3
A ||= B
A= $options{"maxpixels"}B= $options{"width"} * $options{"height"}
ABresult
1X1
011
000
461 $options{'pixels'} ||=
462 int( rand( $options{'maxpixels'} - $options{'minpixels'} + 1 ) ) +
463 0 ▶ $options{'minpixels'};
Condition0%0/3
$options{"pixels"} ||= int(rand $options{"maxpixels"} - $options{"minpixels"} + 1) + $options{"minpixels"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"pixels"} ||= int(rand $options{"maxpixels"} - $options{"minpixels"} + 1) + $options{"minpixels"}
$options{"pixels"} int(rand $options{"maxpixels"} - $options{"minpixels"} + 1) + $options{"minpixels"}
Truth table0%0/3
A ||= B
A= $options{"pixels"}B= int(rand $options{"maxpixels"} - $options{"minpixels"} + 1) + $options{"minpixels"}
ABresult
1X1
011
000
464  
465 0 ▶ $options{'bgcolor'} ||= _color();
Condition0%0/3
$options{"bgcolor"} ||= _color()
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"bgcolor"} ||= _color()
$options{"bgcolor"} _color()
Truth table0%0/3
A ||= B
A= $options{"bgcolor"}B= _color()
ABresult
1X1
011
000
466 0 ▶ $options{'fgcolor'} ||= _color();
Condition0%0/3
$options{"fgcolor"} ||= _color()
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"fgcolor"} ||= _color()
$options{"fgcolor"} _color()
Truth table0%0/3
A ||= B
A= $options{"fgcolor"}B= _color()
ABresult
1X1
011
000
467  
468 0 my $image = GD::Image->new( $options{'width'}, $options{'height'} );
469  
470 0 my $bgcolor = $image->colorAllocate( @{ $options{'bgcolor'} } );
471 0 my $fgcolor = $image->colorAllocate( @{ $options{'fgcolor'} } );
472  
473 0 $image->rectangle( 0, 0, $options{'width'}, $options{'height'}, $bgcolor );
474  
475 0 ▶ for ( my $i = 0 ; $i < $options{'pixels'} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $options{"pixels"}) 0 0 0
476 0 my $x = int( rand( $options{'width'} + 1 ) );
477 0 my $y = int( rand( $options{'height'} + 1 ) );
478  
479 0 $image->setPixel( $x, $y, $fgcolor );
480 }
481  
482 0 return $image->png();
483  
484 0 ▶ sub _color {
Subroutine _color: not called CC=1 SCAR=6.9
485 0 return [ int( rand(256) ), int( rand(256) ), int( rand(256) ) ];
486 }
487 }
488  
489 ################################################################################
490 # _shuffle()
491 ################################################################################
492 2636 ▶sub _shuffle {
Subroutine _shuffle: called CC=3 SCAR=11.0
493 2636 my $array = shift;
494  
495 2636 ▶ for ( my $i = @$array - 1 ; $i >= 0 ; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 66043 2636 68679
496 66043 my $j = int( rand( $i + 1 ) );
497  
498 66043 ▶ @$array[ $i, $j ] = @$array[ $j, $i ] if $i != $j;
Branch: 1 branch
BranchTrueFalseTotal
if $i != $j 57806 8237 66043
499 }
500 }
501  
502 10 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<set> 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<Data::Random::WordList>
832  
833 =cut
↑ Summary Random/WordList.pm »