PHP Classes

Sample Data Generator: Generating random sample data based on rules

Recommend this page to a friend!
  Info   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 59%Total: 858 All time: 4,066 This week: 206Up
Version License Categories
tsample 1.0BSD LicenseStatistics
Description Author

This class provides a set of base methods for defining rules to generate a meaningful sample dataset for testing purposes or for performing statistical analysis.

Potential applications may be:

- Generate sample customer data to populate a database for application testing purposes
- Generate statistically random samples from a marketing database, for further analysis
- Generate random datasets for modelling simulations

Picture of Ignatius Teo
Name: Ignatius Teo is available for providing paid consulting. Contact Ignatius Teo .
Classes: 2 packages by
Country: Australia Australia
Age: 56
All time rank: 51 in Australia Australia
Week rank: 260 Down4 in Australia Australia Down
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

NAME ==== TSample VERSION ======= 10th Jan 2004, v0.1 SYNOPSIS ======== This class provides a set of base methods for creating rules to generate a meaningful sample dataset for testing or for statistical analysis. The key feature of this class is that it allows you to specify rulesets for generating sample data, which is meaningful. Potential applications: . generate sample customer data for populating a database for application testing purposes; . generate statistically random samples from a marketing database, for further analysis; . generate random datasets for modelling simulations; DESCRIPTION =========== This class provides a set of base methods for creating rulesets to generate sample data. This class can be used to generate base sample data for importing into a database for testing purposes. Another possible application of this class can be used in statistical sampling to generate random samples from a database for further analysis. The following base method are provided: . range($min, $max) Returns a pseudo-random number between $min and $max . random($min, $max) Alias for range() . choice($choices, $min_choices, $max_choices, $sep) Returns an array of choices between $min and $max, with each array element separated by commas (default) . datetime($d1, $d2) Returns a random datetime string between timestamps $d1 and $d2 . dob($min, $max) Returns a date of birth between $min and $max age . number($length) Returns a string of random numbers to specified length . alpha($length) Returns a string of random letters (a-z) to the specified length . alphanum($length) Returns an string of printable ASCII alphanumeric characters to the specified length . as_is($value) Returns the specified value "as-is". This is a dummy method for passing the specified value back to the generate() method . generate($ruleset, $rows) This is the heart of the class. The generate() method takes the specified ruleset and generates a sample dataset (specified by $rows) USAGE ===== <?php include "tsample.php"; $ruleset = array( $fieldname => array($method, $params...), . . . ); TSample::generate($ruleset, $num_rows); ?> See example1.php and example2.php for how to define a ruleset. REQUIREMENTS ============ PHP3/4 CHANGELOG ========= 0.1 Initial release (this release) FILES ===== tsample.php Main class example1.php A very basic example example2.php Slightly more advanced example AUTHOR ======= Ignatius Teo <> LICENSE ======= Copyright (C)2004, Ignatius Teo <> All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. COPYRIGHT ========= Copyright (C) 2004 Ignatius Teo <> All Rights Reserved $Id: README,v 1.2 2004/12/04 00:00:54 Owner Exp $
  Files folder image Files  
File Role Description
Accessible without login Plain text file example1.php Example Basic example
Accessible without login Plain text file example2.php Example Advanced example
Accessible without login Plain text file README Doc. ReadMe File
Plain text file tsample.php Class Main class

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:4,066
This week:206Up
 User Ratings  
 All time