Data::Random(3pm)
π Data::Random β the perl module that literally makes stuff up π
okay bestie, gather round, because this is the manpage for Data::Random (that's the 3pm perl manual page, iykyk) β the module you call when you need random data and you're too iconic to type it out yourself. It's a perl module, it's been around since the year 2000, and it is serving.
β¨ NAME β¨
Data::Random β a Perl module to generate random data. That's it, that's the whole vibe. π
π SYNOPSIS π
here's the whole thing, exactly as it comes, no notes:
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);
look at that. look at her go. π¦
πΈ DESCRIPTION πΈ
A module used to generate random data. Useful mostly for test programs. So like β when your test fixtures are boring and you need chaos but β¨controlledβ¨ chaos, this is her. π«Ά
π METHODS π
these are the main characters. one by one, no skipping, we are not doing that. π
π rand_words()
returns a list of random words, pulled from a wordlist. parameters below, bestie:
wordlistβ the path to the wordlist file. On Debian systems one can be found at/usr/share/dict/words. You can also optionally supply aData::Random::WordListobject to keep a persistent wordlist. The default is the wordlist distributed with this module.minβ the minimum number of words to return. The default is1.maxβ the maximum number of words to return. The default is1.sizeβ the number of words to return. The default is1. If you supply a value for'size', then'min'and'max'aren't paid attention to.shuffleβ whether or not the words should be randomly shuffled. Set this to0if you don't want the words shuffled. The default is1.Random::Data::WordListreturns 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.
π ngl thatsize-beats-min-and-maxthing ripples through this whole entire manpage, so clock it now and you'll be fine forever.
π§ rand_chars()
called in a list context it returns a list of random characters given a set of characters. In a scalar context it returns a string of random characters. parameters:
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:
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
minβ the minimum number of characters to return. The default is0.maxβ the maximum number of characters to return. The default is the size of the set.sizeβ the number of characters to return. The default is1. If you supply a value for'size', then'min'and'max'aren't paid attention to.shuffleβ whether or not the characters should be randomly shuffled. Set this to0if you want the characters to stay in the order received. The default is1.
she does both list AND scalar context, she's versatile, she contains multitudes. β¨
π rand_set()
returns a random set of elements given an initial set. parameters:
setβ the set of strings to be used. This should be a reference to an array of strings.minβ the minimum number of strings to return. The default is0.maxβ the maximum number of strings to return. The default is the size of the set.sizeβ the number of strings to return. The default is1. If you supply a value for'size', then'min'and'max'aren't paid attention to.shuffleβ whether or not the strings should be randomly shuffled. Set this to0if you want the strings to stay in the order received. The default is1.
π rand_enum()
returns a single random element given an initial set. parameters:
setβ the set of strings to be used. This should be a reference to an array of strings. The"set"key will be assumed if the array reference is passed as the only argument.
π«Ά that last bit is the shortcut from the synopsis:rand_enum( \@set )β you don't even have to say the wordset. queen behavior.
π¦ rand_date()
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. options below control the date range. examples, verbatim:
# 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' );
parameters:
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;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;
β rand_time()
returns a random time in the form "HH:MM:SS". 24 hour times are supported. options below control the time range. 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' );
parameters:
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 is00:00:00;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 is23:59:59;
π rand_datetime()
returns a random date and time in the form "YYYY-MM-DD HH:MM:SS". options below control the date/time range. 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' );
parameters:
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;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;
π₯ rand_image()
returns a random image. Currently only PNG images are supported. parameters:
minwidthβ the minimum width of the image. The default is1.maxwidthβ the maximum width of the image. The default is100.widthβ the width of the image. If you supply a value for'width', then'minwidth'and'maxwidth'aren't paid attention to.minheightβ the minimum height of the image. The default is1.maxheightβ the maximum height of the image. The default is100.heightβ the height of the image. If you supply a value for'width', then'minwidth'and'maxwidth'aren't paid attention to.minpixelsβ the minimum number of random pixels to display on the image. The default is0.maxpixelsβ the maximum number of random pixels to display on the image. The default iswidth * height.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.bgcolorβ the background color of the image. The value must be a reference to an RGB array where each element is an integer between0and255(eg.[ 55, 120, 255 ]).fgcolorβ the foreground color of the image. The value must be a reference to an RGB array where each element is an integer between0and255(eg.[ 55, 120, 255 ]).
π heads up bestie: yes, theheightdescription up there really does talk about'width','minwidth'and'maxwidth'. That's what the page says, we do not fix, we do not edit, we report. π
π VERSION π
0.12 β she's giving vintage but she still runs. β¨
π«Ά AUTHOR π«Ά
Originally written by: Adekunle Olonoh
Currently maintained by: Buddy Burden (barefoot@cpan.org), starting with version 0.06
π CREDITS π
the girls that helped make her happen, in the original nesting:
- Hiroki Chalfant
- David Sarno
- Michiel Beijen
π COPYRIGHT π
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.
π SEE ALSO π
Data::Random::WordList
and that's the whole page, no cap. π
this perl manual page shipped as perl v5.40.1 and it's dated 2026-03-12 β so like, she's current, she's maintained, she ate and left no crumbs. go generate something random, bestie. π¦βπ
π¦ where this page comes from
- ubuntu stonking: libdata-random-perl 0.15-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms