The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Data::RandomPerson - Create random person data.


  use Data::RandomPerson;

  my $r = Data::RandomPerson->new();
  my $p = $r->create();
  print $p->{firstname}, ' ', $p->{lastname}, "\n";



Returns an object that can be used to create random people and return the data in a hash. The data is a hash reference with the following keys:


This is either 'm' or 'f'


The age of the person, as an integer.


The date of birth of the person based upon how old they are in the current year. The month and day portion are selected randomly.


The person's first name based on their gender. The names are picked from Data::RandomPerson::Name::{Male,Female} unless other classes are supplied to the new method.


The person's last name. The names are picked from Data::RandomPerson::Name::Last unless another class is supplied to the new method.


The person's title based on their age and gender.

Constructors and initialization


Create the Data::RandomPerson object. By default Data::RandomPerson::Names::{Male,Female,Last} are used to supply the male, female and last names.

If you want to generate names from a specific type, you can use the 'type' parameter like this:

    my $r = Data::RandomPerson->new(type => 'Spanish');

The list of available types is obtained by calling available_types(). Only name lists that have collections for female, male and last names can be specified here.

You can also choose to override the classes for last names, female or male names. To do that, use the keys 'female', 'male', and 'last'. Please note that in this case you need to specify the FULL class name. For instance to create persons using a Celtic first name, use:

    my $r = Data::RandomPerson->new(
        female => 'Data::RandomPerson::Names::CelticFemale',
        male   => 'Data::RandomPerson::Names::CelticMale',

Class and object methods


Returns 'm' or 'f' with equal probability. This can be overridden to adjust the ratio on males to females in your target population.


Returns an age between 1 and 100. This can be overridden to return values in the range required of your target population.


Calculates the date of birth from the age in the format YYYY-MM-DD. The YYYY value is the current year minus the age, MM and DD and random, valid, values. This method should not need to be overridden unless the date format is not what you require.


Return a suitable title based on the age and gender of the person. The ratios used here are completely made up and until I can get hold of some hard data, like a copy of the electoral roll, it can only be a best guess.


Returns a last name from the class loaded by the init() method. You should not need to override this method.


Returns a first name of the correct gender from the class loaded by the init() method. You should not need to override this method.


Returns a newly created person as a hash reference with the following keys: gender, age, dob, firstname, lastname and title. A new person is returned for each call of the method although there is no guarantee of uniqueness.


Returns the list of available name types. These are the types you can request in a call to new(). Usage:

    my @types = Data::RandomPerson::available_types();


Unknown argument 'XXX' passed to new

There are only three arguments that can be optionally passed to new. These are 'male', 'female' and 'last' and they should be the classes that will be used to get the male, female and last names.

Unable to load 'XXX': ...

A class given to load instead of the default class could not be loaded. Hopefully a sensible reason will be given.


Peter Hickman (


Copyright (c) 2005, Peter Hickman.

Copyright (c) 2014, Michiel Beijen.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.