1Random(3) User Contributed Perl Documentation Random(3)
2
3
4
6 Data::Random - Perl module to generate random data
7
9 use Data::Random qw(:all);
10
11 my @random_words = rand_words( size => 10 );
12
13 my @random_chars = rand_chars( set => 'all', min => 5, max => 8 );
14
15 my @random_set = rand_set( set => \@set, size => 5 );
16
17 my $random_enum = rand_enum( set => \@set );
18
19 my $random_date = rand_date();
20
21 my $random_time = rand_time();
22
23 my $random_datetime = rand_datetime();
24
25 open(FILE, ">rand_image.png") or die $!;
26 binmode(FILE);
27 print FILE rand_image( bgcolor => [0, 0, 0] );
28 close(FILE);
29
31 A module used to generate random data. Useful mostly for test
32 programs.
33
35 rand_words()
36 This returns a list of random words given a wordlist. See below for
37 possible parameters.
38
39 · wordlist - the path to the wordlist file. A lot of systems have
40 one at /usr/dict/words. You can also optionally supply a
41 Data::Random::WordList object to keep a persistent wordlist. The
42 default is the wordlist distributed with this module.
43
44 · min - the minimum number of words to return. The default is 1.
45
46 · max - the maximum number of words to return. The default is 1.
47
48 · size - the number of words to return. The default is 1. If you
49 supply a value for 'size', then 'min' and 'max' aren't paid
50 attention to.
51
52 · shuffle - whether or not the words should be randomly shuffled.
53 Set this to 0 if you don't want the words shuffled. The default is
54 1. Random::Data::WordList returns words in the order that they're
55 viewed in the word list file, so shuffling will make sure that the
56 results are a little more random.
57
58 rand_chars()
59 This returns a list of random characters given a set of characters.
60 See below for possible parameters.
61
62 · set - the set of characters to be used. This value can be either a
63 reference to an array of strings, or one of the following:
64
65 alpha - alphabetic characters: a-z, A-Z
66 upperalpha - upper case alphabetic characters: A-Z
67 loweralpha - lower case alphabetic characters: a-z
68 numeric - numeric characters: 0-9
69 alphanumeric - alphanumeric characters: a-z, A-Z, 0-9
70 char - non-alphanumeric characters: # ~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ `
71 all - all of the above
72
73 · min - the minimum number of characters to return. The default is
74 0.
75
76 · max - the maximum number of characters to return. The default is
77 the size of the set.
78
79 · size - the number of characters to return. The default is 1. If
80 you supply a value for 'size', then 'min' and 'max' aren't paid
81 attention to.
82
83 · shuffle - whether or not the characters should be randomly
84 shuffled. Set this to 0 if you want the characters to stay in the
85 order received. The default is 1.
86
87 rand_set()
88 This returns a random set of elements given an initial set. See below
89 for possible parameters.
90
91 · set - the set of strings to be used. This should be a reference to
92 an array of strings.
93
94 · min - the minimum number of strings to return. The default is 0.
95
96 · max - the maximum number of strings to return. The default is the
97 size of the set.
98
99 · size - the number of strings to return. The default is 1. If you
100 supply a value for 'size', then 'min' and 'max' aren't paid
101 attention to.
102
103 · shuffle - whether or not the strings should be randomly shuffled.
104 Set this to 0 if you want the strings to stay in the order
105 received. The default is 1.
106
107 rand_enum()
108 This returns a random element given an initial set. See below for
109 possible parameters.
110
111 · set - the set of strings to be used. This should be a reference to
112 an array of strings.
113
114 rand_date()
115 This returns a random date in the form "YYYY-MM-DD". 2-digit years are
116 not currently supported. Efforts are made to make sure you're returned
117 a truly valid date--ie, you'll never be returned the date February
118 31st. See the options below to find out how to control the date range.
119 Here are a few examples:
120
121 # returns a date somewhere in between the current date, and one year from the current date
122 $date = rand_date();
123
124 # returns a date somewhere in between September 21, 1978 and September 21, 1979
125 $date = rand_date( min => '1978-9-21' );
126
127 # returns a date somewhere in between September 21, 1978 and the current date
128 $date = rand_date( min => '1978-9-21', max => 'now' );
129
130 # returns a date somewhere in between the current date and September 21, 2008
131 $date = rand_date( min => 'now', max => '2008-9-21' );
132
133 See below for possible parameters.
134
135 · min - the minimum date to be returned. It should be in the form
136 "YYYY-MM-DD" or you can alternatively use the string "now" to
137 represent the current date. The default is the current date;
138
139 · max - the maximum date to be returned. It should be in the form
140 "YYYY-MM-DD" or you can alternatively use the string "now" to
141 represent the current date. The default is one year from the
142 minimum date;
143
144 rand_time()
145 This returns a random time in the form "HH:MM:SS". 24 hour times are
146 supported. See the options below to find out how to control the time
147 range. Here are a few examples:
148
149 # returns a random 24-hr time (between 00:00:00 and 23:59:59)
150 $time = rand_time();
151
152 # returns a time somewhere in between 04:00:00 and the end of the day
153 $time = rand_time( min => '4:0:0' );
154
155 # returns a time somewhere in between 8:00:00 and the current time (if it's after 8:00)
156 $time = rand_time( min => '12:00:00', max => 'now' );
157
158 # returns a date somewhere in between the current time and the end of the day
159 $time = rand_time( min => 'now' );
160
161 See below for possible parameters.
162
163 · min - the minimum time to be returned. It should be in the form
164 "HH:MM:SS" or you can alternatively use the string "now" to
165 represent the current time. The default is 00:00:00;
166
167 · max - the maximum time to be returned. It should be in the form
168 "HH:MM:SS" or you can alternatively use the string "now" to
169 represent the current time. The default is 23:59:59;
170
171 rand_datetime()
172 This returns a random date and time in the form "YYYY-MM-DD HH:MM:SS".
173 See the options below to find out how to control the date/time range.
174 Here are a few examples:
175
176 # returns a date somewhere in between the current date/time, and one year from the current date/time
177 $datetime = rand_datetime();
178
179 # returns a date somewhere in between 4:00 September 21, 1978 and 4:00 September 21, 1979
180 $datetime = rand_datetime( min => '1978-9-21 4:0:0' );
181
182 # returns a date somewhere in between 4:00 September 21, 1978 and the current date
183 $datetime = rand_datetime( min => '1978-9-21 4:0:0', max => 'now' );
184
185 # returns a date somewhere in between the current date/time and the end of the day September 21, 2008
186 $datetime = rand_datetime( min => 'now', max => '2008-9-21 23:59:59' );
187
188 See below for possible parameters.
189
190 · min - the minimum date/time to be returned. It should be in the
191 form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string
192 "now" to represent the current date/time. The default is the
193 current date/time;
194
195 · max - the maximum date/time to be returned. It should be in the
196 form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string
197 "now" to represent the current date/time. The default is one year
198 from the minimum date/time;
199
200 rand_image()
201 This returns a random image. Currently only PNG images are supported.
202 See below for possible parameters.
203
204 · minwidth - the minimum width of the image. The default is 1.
205
206 · maxwidth - the maximum width of the image. The default is 100.
207
208 · width - the width of the image. If you supply a value for 'width',
209 then 'minwidth' and 'maxwidth' aren't paid attention to.
210
211 · minheight - the minimum height of the image. The default is 1.
212
213 · maxheight - the maximum height of the image. The default is 100.
214
215 · height - the height of the image. If you supply a value for
216 'width', then 'minwidth' and 'maxwidth' aren't paid attention to.
217
218 · minpixels - the minimum number of random pixels to display on the
219 image. The default is 0.
220
221 · maxpixels - the maximum number of random pixels to display on the
222 image. The default is width * height.
223
224 · pixels - the number of random pixels to display on the image. If
225 you supply a value for 'pixels', then 'minpixels' and 'maxpixels'
226 aren't paid attention to.
227
228 · bgcolor - the background color of the image. The value must be a
229 reference to an RGB array where each element is an integer between
230 0 and 255 (eg. [ 55, 120, 255 ]).
231
232 · fgcolor - the foreground color of the image. The value must be a
233 reference to an RGB array where each element is an integer between
234 0 and 255 (eg. [ 55, 120, 255 ]).
235
237 0.05
238
240 Adekunle Olonoh, koolade@users.sourceforge.net
241
243 Hiroki Chalfant David Sarno
244
246 Copyright (c) 2000 Adekunle Olonoh. All rights reserved. This program
247 is free software; you can redistribute it and/or modify it under the
248 same terms as Perl itself.
249
251 Data::Random::WordList
252
254 Hey! The above document had some coding errors, which are explained
255 below:
256
257 Around line 600:
258 =back doesn't take any parameters, but you said =back 4
259
260 Around line 637:
261 =back doesn't take any parameters, but you said =back 4
262
263 Around line 666:
264 =back doesn't take any parameters, but you said =back 4
265
266 Around line 679:
267 =back doesn't take any parameters, but you said =back 4
268
269 Around line 710:
270 =back doesn't take any parameters, but you said =back 4
271
272 Around line 741:
273 =back doesn't take any parameters, but you said =back 4
274
275 Around line 772:
276 =back doesn't take any parameters, but you said =back 4
277
278 Around line 825:
279 =back doesn't take any parameters, but you said =back 4
280
281
282
283perl v5.12.1 2003-02-22 Random(3)