|Classes of Alexander Selifonov||PHP Random people||README.md||Download|
Extensible Random People Generator
Class for generating random people data, for populating test databases and similar purposes (for example create company fake employees list, or obfuscating personnel data before sending outside company)
Simple module for generating randomized "human" data: First name, Last name, middle name (if needed), birthdate in desired age range.
Functions for generating any additional attributes can be easily added. For example. you can add "department", "duty" or "salary" generators to make full emlpoyee data.
You can add your language modules just by creating class.randomdata.lang-XX.php file (XX must be your language abbreviation) and including it to your script. Example content of implementation for on "language":
Or you can add some 'basic' names to earlier pre-defined lists. For examle, to add some new last-names to the 'english' list:
If last name for males and females has differense, you can pass "modifier" function name, that will correctly modify base last name by adding respective postfix, "lastname_modifier" element must pass "modifier" user function name that will receives two parameters - "base" last name and gender ('m' or 'f') and returns correct lastname for passed gender. For example, russian last names based on common "base" usually have different: endings:
So a simplest modifier function (for russian last names) should at least add "a" at the end of a last name for female (in most cases, with exclusions).
Setting limits for birthdate
By default random birth date range is between 1 and 60 years ago from current date. (see a var $config in the main class module). To change these borders you can call function RandomData::getRandomDate() explicitly passing your min and max year values. But when "integrate" function getPerson() for employee list (for instance), you will want to make "mature" people. So you can pass your limits in $options parameter :
Or you can call setConfig() method before any getPerson() using :
Adding user attributes
It is possible to add new atributes to be randomly generated for the object (person). For example, you may need "department id", "salary" or a start working date for the full employee description.
Getting randomized person data
First, You can call single function for each person attribute:
Second, you call static method getPerson() that wll return associative array holding randomized values for all attributes - "built-in" and added by you :
Family tree generation
Additional class was included to generate random "family trees", begining from "start" person, with his/her parents, grand-parents etc. This class implemented as separated module, class.randomdata.ftree.php This module contains class RandomFtree that extends base class RandomData. It has one main public method familyTree(), that will return an array with "family tree" people.
Each row in this array is an array too, that contains one or more "person" blocks. There is one person in the first row - this is a "start" person of a tree. Each next row contains parents (father first, then mother) for all person(s) in the previous row. It is possible to generate death date too. To turn it on. pass $options with non-empty 'death' element:
Here we want to create two generations (parents and grand-parents) from start person, with "death date", having "maximal" age of 80 years. One note: if year of created death date is equal or greather than current year, person will be treated as "alive" (no death date).
Working sample demonstrating created family tree provided in "examples" folder : examples/family_tree.php
To visualize family tree i used CSS3 tricks from http://codepen.io/Pestov/pen/BLpgm :
Working examples can be found in examples folder.
Distributed under BSD (v3) License : http://opensource.org/licenses/BSD-3-Clause