PHP Classes


Recommend this page to a friend!
  Classes of Ignatius Teo   Sample Data Generator   README   Download  
Role: Documentation
Content type: text/plain
Description: ReadMe File
Class: Sample Data Generator
Generating random sample data based on rules
Author: By
Last change:
Date: 19 years ago
Size: 4,430 bytes


Class file image Download
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 $