Data::Random(3pm) | User Contributed Perl Documentation | Data::Random(3pm) |
Data::Random - Perl module to generate random data
use Data::Random qw(:all); my @random_words = rand_words( size => 10 ); my @random_chars = rand_chars( set => 'all', min => 5, max => 8 ); my $string = rand_chars( set => 'all', min => 5, max => 8 ); my @random_set = rand_set( set => \@set, size => 5 ); my $random_enum = rand_enum( set => \@set ); my $random_enum = rand_enum( \@set ); # shortcut my $random_date = rand_date(); my $random_time = rand_time(); my $random_datetime = rand_datetime(); open(my $file, ">", "rand_image.png") or die $!; binmode($file); print $file rand_image( bgcolor => [0, 0, 0] ); close($file);
A module used to generate random data. Useful mostly for test programs.
This returns a list of random words given a wordlist. See below for possible parameters.
When called in a list context this returns a list of random characters given a set of characters. In a scalar context it returns a string of random characters. See below for possible parameters.
alpha - alphabetic characters: a-z, A-Z upperalpha - upper case alphabetic characters: A-Z loweralpha - lower case alphabetic characters: a-z numeric - numeric characters: 0-9 alphanumeric - alphanumeric characters: a-z, A-Z, 0-9 char - non-alphanumeric characters: # ~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ \ ` misc - same as 'char' all - all of the above
This returns a random set of elements given an initial set. See below for possible parameters.
This returns a random element given an initial set. See below for possible parameters.
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:
# returns a date somewhere in between the current date, and one year from the current date $date = rand_date(); # returns a date somewhere in between September 21, 1978 and September 21, 1979 $date = rand_date( min => '1978-9-21' ); # returns a date somewhere in between September 21, 1978 and the current date $date = rand_date( min => '1978-9-21', max => 'now' ); # returns a date somewhere in between the current date and September 21, 2008 $date = rand_date( min => 'now', max => '2008-9-21' );
See below for possible parameters.
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:
# returns a random 24-hr time (between 00:00:00 and 23:59:59) $time = rand_time(); # returns a time somewhere in between 04:00:00 and the end of the day $time = rand_time( min => '4:0:0' ); # returns a time somewhere in between 8:00:00 and the current time (if it's after 8:00) $time = rand_time( min => '12:00:00', max => 'now' ); # returns a date somewhere in between the current time and the end of the day $time = rand_time( min => 'now' );
See below for possible parameters.
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:
# returns a date somewhere in between the current date/time, and one year from the current date/time $datetime = rand_datetime(); # returns a date somewhere in between 4:00 September 21, 1978 and 4:00 September 21, 1979 $datetime = rand_datetime( min => '1978-9-21 4:0:0' ); # returns a date somewhere in between 4:00 September 21, 1978 and the current date $datetime = rand_datetime( min => '1978-9-21 4:0:0', max => 'now' ); # returns a date somewhere in between the current date/time and the end of the day September 21, 2008 $datetime = rand_datetime( min => 'now', max => '2008-9-21 23:59:59' );
See below for possible parameters.
This returns a random image. Currently only PNG images are supported. See below for possible parameters.
0.12
Originally written by: Adekunle Olonoh
Currently maintained by: Buddy Burden (barefoot@cpan.org), starting with version 0.06
Hiroki Chalfant David Sarno Michiel Beijen
Copyright (c) 2000-2011 Adekunle Olonoh. Copyright (c) 2011-2015 Buddy Burden. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Data::Random::WordList
2018-07-20 | perl v5.26.2 |