/SPF_Random.php
PHP | 353 lines | 198 code | 73 blank | 82 comment | 18 complexity | 4a7075bd07840688485ba2fa83385621 MD5 | raw file
- <?php
- /**
- * SPF_Random
- * @package spf
- * @author Simon Downes <simon@simondownes.co.uk>
- * @copyright Copyright (c) 2008, Simon Downes
- * @license http://www.opensource.org/licenses/mit-license.php
- */
-
- /**
- * Random data generator class.
- *
- * @package spf
- * @author Simon Downes <simon@simondownes.co.uk>
- * @copyright Copyright (c) 2008, Simon Downes
- * @license http://www.opensource.org/licenses/mit-license.php
- */
- final class SPF_Random {
-
- private static $boys = array(
- 'Aaron','Adam','Adrian','Aidan','Alan','Albert','Alexander','Andrew','Anthony','Arthur','Barry','Benjamin','Brian','Chandler',
- 'Charles','Chrisopher','Christian','Clarke','Claudius','Clive','Colin','Connor','Craig','Dale','Damien','Daniel','David',
- 'Declan','Derek','Dominic','Dylan','Edmund','Edward','Eric','Ethan','Evan','Fredrick','Gallahad','Gareth','Garth','Gary',
- 'Gavin','George','Gordon','Graham','Gregory','Harry','Hayden','Ian','Jack','James','Jason','Jeremy','Jonathan','Jordon',
- 'Joseph','Joshua','Julian','Justin','Kenneth','Kevin','Kyle','Kyle','Lancelot','Leonardo','Liam','Logan','Luke','Malcolm',
- 'Marcus','Mark','Matthew','Michael','Nathan','Neil','Nicholas','Nigel','Octavius','Odin','Oliver','Owen','Patrick','Paul',
- 'Pedro','Peter','Phillip','Richard','Robert','Roger','Ryan','Samuel','Scott','Sean','Shane','Simon','Steven','Terry',
- 'Thomas','Timothy','Tony','Trevor','William','Plebie'
- );
-
- private static $girls = array(
- 'Abigail', 'Adriana', 'Alexandra', 'Alexis', 'Allison', 'Alyssa', 'Amanda', 'Amber', 'Amelia', 'Angela', 'Anna', 'Anne', 'Ashley',
- 'Audrey', 'Brianna', 'Brooke', 'Carol', 'Caroline', 'Catherine', 'Chloe', 'Claire', 'Danielle', 'Dawn', 'Deborah', 'Diana',
- 'Diane', 'Dorothy', 'Elizabeth', 'Ella', 'Emily', 'Emma', 'Erin', 'Gabrielle', 'Gemma', 'Georgia', 'Grace', 'Haley', 'Hannah',
- 'Helen', 'Isabella', 'Isabelle', 'Jackie', 'Janet', 'Jasmine', 'Jenna', 'Jessica', 'Jordan', 'Judith', 'Julia', 'Kaitlyn',
- 'Katherine', 'Kayla', 'Kaylee', 'Kylie', 'Lauren', 'Lily', 'Louise', 'Madeline', 'Madison', 'Mandy', 'Marie', 'Marissa',
- 'Mary', 'Megan', 'Michelle', 'Nadia', 'Natalie', 'Nicole', 'Olivia', 'Paula', 'Rachel', 'Rebecca', 'Rose', 'Sabrina', 'Sally',
- 'Samantha', 'Sandra', 'Sarah', 'Sharon', 'Sophia', 'Stephanie', 'Sydney', 'Tabitha', 'Tanya', 'Vicky', 'Victoria', 'Zoe'
- );
-
- private static $surnames = array(
- 'Abbott', 'Adams', 'Ashton', 'Bacon', 'Baggio', 'Bailey', 'Baker', 'Bale', 'Barker', 'Barnbrook', 'Beckingham', 'Bedford', 'Bell',
- 'Black', 'Blackburn', 'Blackwell', 'Bradford', 'Brandon', 'Britten', 'Brooks', 'Brown', 'Burke', 'Butler', 'Butterworth',
- 'Byrne', 'Campbell', 'Carpenter', 'Carter', 'Clooney', 'Cole', 'Coleman', 'Collier', 'Cooper', 'Cottle', 'Crocker', 'Cross',
- 'Davis', 'Day', 'Dixon', 'Dobson', 'Dolman', 'Doyle', 'Eastwood', 'Edwards', 'Einstein', 'Everest', 'Fairbanks', 'Ferguson',
- 'Fields', 'Flynn', 'Ford', 'Frost', 'Furmanski', 'Garton', 'Gibbons', 'Golding', 'Goldsmith', 'Goodwin', 'Grant', 'Gray',
- 'Griffiths', 'Hall', 'Hamilton', 'Harris', 'Heston', 'Hill', 'Holdstock', 'Holmes', 'Hopper', 'Houghton', 'Howard', 'Hudson',
- 'Hunt', 'Hunter', 'Husband', 'Hutchinson', 'Ivory', 'Jefferies', 'Johnson', 'Jones', 'Knight', 'Lamprell', 'Larkin', 'Lewis',
- 'Littlejohn', 'Littlewood', 'Lowe', 'Maddison', 'Marshall', 'Martin', 'Mason', 'McFadyen', 'Mclaren', 'McPleb', 'Merricks',
- 'Middleton', 'Monk', 'Montoya', 'Moss', 'Murphy', 'Murray', 'Nash', 'Nelson', 'Newman', 'Newton', 'Nicholls', 'Norris',
- 'Oakley', 'O\'Connor', 'O\'Dell', 'O\'Donnell', 'O\'Neil', 'Parker', 'Parry', 'Parsons', 'Pearson', 'Perry', 'Pert', 'Philips',
- 'Piper', 'Powers', 'Pridmore', 'Proctor', 'Reeves', 'Richards', 'Riley', 'Roberts', 'Robertson', 'Robinson', 'Robson', 'Rogers',
- 'Sadler', 'Saunders', 'Scott', 'Sheppard', 'Shields', 'Shuttleworth', 'Simpson', 'Smith', 'Stagg', 'Stevens', 'Street',
- 'Taylor', 'Templeton', 'Thompson', 'Tucker', 'Turner', 'Vincent', 'Walker', 'Wallace', 'Walsh', 'Warner', 'Watson',
- 'Webb', 'Wenham', 'White', 'Whitehouse', 'Whittle', 'Wilkinson', 'Williams', 'Wilson', 'Young'
- );
-
- private static $roads = array(
- 'Addison', 'Albert', 'Alders', 'Austin', 'Baker', 'Bishops', 'Brunswick', 'Buckhurst', 'Buckingham', 'Charlwoods', 'Chester', 'Church',
- 'Clifton', 'Crossways', 'Edward', 'Elm', 'Farm', 'Garland', 'George', 'Goldstone', 'Green', 'Grove', 'Harvest', 'Harwoods', 'Heathcote',
- 'Herontye', 'Highfield', 'Imberhorne', 'Kennedy', 'Kings', 'Lansdowne', 'Livingstone', 'Lyndhurst', 'Manor', 'Maple', 'Mill',
- 'Morton', 'Oak', 'Orchard', 'Palm', 'Park', 'Portland', 'Queens', 'Regent', 'Richmond', 'Sackville', 'Sandhurst', 'Shakespeare',
- 'Somerset', 'Southlands', 'Springfield', 'Stanley', 'Station', 'Sycamore', 'Tenneson', 'Victoria', 'Westbourne', 'Willow',
- 'Windmill', 'Windsor', 'Woodbury', 'Wordsworth', 'York'
- );
-
- private static $road_suffix = array('Road','Avenue','Street','Close','Drive','Walk','Cresent','Hill','Lane','Parade','Way','Rise');
-
- private static $places = array(
- 'Bedfordshire' => array('Bedford', 'Luton', 'Dunstable', 'Leighton Buzzard', 'Biggleswade', 'Sandy'),
- 'Berkshire' => array('Reading', 'Bracknell', 'Maidenhead', 'Newbury', 'Windsor', 'Wokingham', 'Abingdon'),
- 'Buckinghamshire' => array('Aylesbury', 'Milton Keynes', 'Slough', 'Buckingham', 'High Wycombe'),
- 'Cambridgeshire' => array('Cambridge', 'Wisbech', 'Ely', 'March', 'Whittlesey', 'Chatteris', 'Linton'),
- 'Cheshire' => array('Chester', 'Stockport', 'Ellesmere Port', 'Birkenhead', 'Wallasey', 'Runcorn', 'Macclesfield', 'Crewe'),
- 'Cornwall' => array('Bodmin', 'Truro', 'Camborne', 'Redruth', 'St. Austell', 'Falmouth', 'Penzance', 'Newquay'),
- 'Cumberland' => array('Carlisle', 'Whitehaven', 'Workington', 'Penrith', 'Keswick', 'Brampton'),
- 'Derbyshire' => array('Derby', 'Chesterfield', 'Ilkeston', 'Swadlincote', 'Buxton', 'Matlock', 'Ashbourne'),
- 'Devon' => array('Exeter', 'Plymouth', 'Torquay', 'Paignton', 'Barnstaple', 'Tiverton', 'Newton Abbot', 'Tavistock'),
- 'Dorset' => array('Dorchester', 'Poole', 'Weymouth', 'Sherborne', 'Wimborne Minster', 'Shaftesbury'),
- 'Durham' => array('Durham', 'Sunderland', 'Stockton-on-Tees', 'Darlington', 'Hartlepool', 'Gateshead', 'Washington'),
- 'Essex' => array('Chelmsford', 'Basildon', 'Romford', 'Southend', 'Colcheter', 'Harlow', 'Brentwood', 'West Ham'),
- 'Gloucestershire' => array('Gloucester', 'Bristol', 'Cheltenham', 'Stroud', 'Cirencester', 'Tewkesbury'),
- 'Hampshire' => array('Winchester', 'Southampton', 'Portsmouth', 'Bournemouth', 'Basingstoke', 'Newport'),
- 'Herefordshire' => array('Hereford', 'Ross-on-Wye', 'Leominster', 'Ledbury', 'Bromyard', 'Kington'),
- 'Hertfordshire' => array('Hertford', 'Watford', 'St. Albans', 'Hemel Hempstead', 'Stevenage', 'Hatfield'),
- 'Huntingdonshire' => array('Huntingdon', 'St. Ives', 'St. Neots', 'Ramsey', 'Yaxley'),
- 'Kent' => array('Maidstone', 'Canterbury', 'Bromley', 'Rochester', 'Margate', 'Folkestone', 'Dover', 'Greenwich'),
- 'Lancashire' => array('Lancaster', 'Liverpool', 'Manchester', 'Preston', 'Bolton', 'Warrington', 'Barrow-in-Furness'),
- 'Leicestershire' => array('Leicester', 'Loughborough', 'Hinckley', 'Melton Mowbray', 'Coalville', 'Lutterworth'),
- 'Lincolnshire' => array('Lincoln', 'Grimsby', 'Scunthorpe', 'Boston', 'Grantham', 'Stamford', 'Skegness', 'Louth'),
- 'Middlesex' => array('City of London', 'Harrow', 'Enfield', 'Staines', 'Ealing', 'Potters Bar', 'Westminster '),
- 'Norfolk' => array('Norwich', 'Great Yarmouth', 'King\'s Lynn', 'Dereham', 'Cromer', 'Hunstanton'),
- 'Northamptonshire' => array('Northampton', 'Peterborough', 'Corby', 'Kettering', 'Wellingborough'),
- 'Northumberland' => array('Alnwick', 'Newcastle-upon-Tyne', 'Morpeth', 'Hexham', 'Berwick-upon-Tweed'),
- 'Nottinghamshire' => array('Nottingham', 'Mansfield', 'Worksop', 'Newark', 'Retford', 'Southwell'),
- 'Oxfordshire' => array('Oxford', 'Banbury', 'Witney', 'Bicester', 'Henley-on-Thames', 'Carterton', 'Thame'),
- 'Rutland' => array('Oakham', 'Uppingham. Cottesmore'),
- 'Shropshire' => array('Shrewsbury', 'Telford', 'Oswestry', 'Bridgnorth', 'Whitchurch', 'Market Drayton', 'Ludlow'),
- 'Somerset' => array('Taunton', 'Bath', 'Weston-super-Mare', 'Yeovil', 'Bridgwater', 'Wells', 'Glastonbury'),
- 'Staffordshire' => array('Stafford', 'Stoke-on-Trent', 'Wolverhampton', 'Walsall', 'Cannock', 'Lichfield'),
- 'Suffolk' => array('Ipswich', 'Bury St. Edmunds', 'Lowestoft', 'Felixstowe', 'Sudbury', 'Haverhill', 'Bungay'),
- 'Surrey' => array('Guildford', 'Croydon', 'Woking', 'Sutton', 'Kingston-on-Thames', 'Wandsworth', 'Wimbledon', 'Brixton'),
- 'Sussex' => array('Chichester', 'Brighton', 'Worthing', 'Crawley', 'Hastings', 'Eastbourne', 'Bognor Regis', 'Horsham'),
- 'Warwickshire' => array('Warwick', 'Birmingham', 'Coventry', 'Nuneaton', 'Rugby', 'Solihull', 'Stratford-upon-Avon'),
- 'Westmorland' => array('Appleby', 'Kendal', 'Windermere', 'Ambleside', 'Kirkby Lonsdale'),
- 'Wiltshire' => array('Trowbridge', 'Salisbury', 'Swindon', 'Chippenham', 'Devizes', 'Marlborough', 'Warminster'),
- 'Worcestershire' => array('Worcester', 'Dudley', 'Kidderminster', 'Stourbridge', 'Halesowen', 'Malvern', 'Evesham'),
- 'North Yorkshire' => array('Northallerton', 'Middlesbrough', 'Scarborough', 'Whitby'),
- 'East Yorkshire' => array('Beverley', 'Hull', 'Bridlington', 'Driffield', 'Hornsea', 'Filey'),
- 'West Yorkshire' => array('Wakefield', 'Leeds', 'Sheffield', 'Bradford', 'Halifax', 'Harrogate')
- ); // places
-
- private static $job_titles_1 = array('Uber','Lead','Senior','Direct','Corporate','Dynamic','Future','Product','National','Regional','Global','Customer','Investor','Dynamic','Return','Legacy','Forward','Internal','Human','Chief','Principal','Associate');
-
- private static $job_titles_2 = array('Brand','Research','Marketing','Directives','Strategy','Implementation','Integration','Functionality','Response','Tactics','Identity','Markets','Group','Division','Applications','Optimization','Operations','Infrastructure','Intranet','Communications','Web','Branding','Quality','Assurance','Mobility','Accounts','Data','Creative','Configuration','Accountability','Interactions','Factors','Usability','Metrics');
-
- private static $job_titles_3 = array('Pleb','Manager','Engineer','Specialist','Director','Coordinator','Administrator','Architect','Analyst','Designer','Planner','Orchestrator','Technician','Developer','Producer','Consultant','Assistant','Facilitator');
-
- private static $lorem = array(
- 'a','ac','accumsan','ad','adipiscing','aenean','aliquam','aliquet','amet','ante','aptent','arcu','at','auctor','augue',
- 'bibendum','blandit','class','commodo','condimentum','congue','consectetuer','consequat','conubia','convallis','cras','cubilia',
- 'cum','curabitur','curae;','cursus','dapibus','diam','dictum','dictumst','dignissim','dis','dolor','donec','dui','duis','egestas',
- 'eget','eleifend','elementum','elit','enim','erat','eros','est','et','etiam','eu','euismod','facilisi','facilisis','fames',
- 'faucibus','felis','fermentum','feugiat','fringilla','fusce','gravida','habitant','habitasse','hac','hendrerit','hymenaeos',
- 'iaculis','id','imperdiet','in','inceptos','integer','interdum','ipsum','justo','lacinia','lacus','laoreet','lectus','leo','libero',
- 'ligula','litora','lobortis','lorem','luctus','maecenas','magna','magnis','malesuada','massa','mattis','mauris','metus','mi',
- 'molestie','mollis','montes','morbi','mus','nam','nascetur','natoque','nec','neque','netus','nibh','nisi','nisl','non','nonummy',
- 'nostra','nulla','nullam','nunc','odio','orci','ornare','parturient','pede','pellentesque','penatibus','per','pharetra','phasellus',
- 'placerat','platea','porta','porttitor','posuere','potenti','praesent','pretium','primis','proin','pulvinar','purus','quam','quis',
- 'quisque','rhoncus','ridiculus','risus','rutrum','sagittis','sapien','scelerisque','sed','sem','semper','senectus','sit','sociis',
- 'sociosqu','sodales','sollicitudin','suscipit','suspendisse','taciti','tellus','tempor','tempus','tincidunt','torquent','tortor',
- 'tristique','turpis','ullamcorper','ultrices','ultricies','urna','ut','varius','vehicula','vel','velit','venenatis','vestibulum',
- 'vitae','vivamus','viverra','volutpat','vulputate'
- );
-
- /**
- * Cannot be instantiated.
- *
- * @return void
- */
- private function __construct() {
- } // __construct
-
- /**
- * Returns a randomly generated first name.
- *
- * @param mixed gender false for a girls name, true for a boys name, not-specified for a random gender.
- * @return string
- */
- public static function forename( $gender = NULL ) {
-
- if( $gender === NULL )
- $gender = mt_rand(0, 1);
-
- if( $gender )
- return self::$boys[array_rand(self::$boys)];
- else
- return self::$girls[array_rand(self::$girls)];
-
- } // forename
-
- /**
- * Returns a randomly generated surname.
- *
- * @return string
- */
- public static function surname() {
-
- return self::$surnames[array_rand(self::$surnames)];
-
- } // surname
-
- /**
- * Returns a randomly generated full name.
- *
- * @param mixed gender false for a girls name, true for a boys name, not-specified for a random gender.
- * @return string
- */
- public static function name( $gender = NULL ) {
-
- return self::forename($gender). ' '. self::surname();
-
- } // name
-
- /**
- * Returns a randomly generated address.
- * The address is returned as a zero-based array of five elements. At least three elements
- * of the array will be filled and empty elements (if any) will appear at the end of the array.
- *
- * @param boolean postcode if true a postcode will be included in the returned array.
- * @return array
- */
- public static function address( $postcode = false ) {
-
- $address = array();
-
- // 1 in 5 addresses will be flats (on average)
- if( mt_rand(1, 5) == 3 )
- $address[] = 'Flat '. mt_rand(1, 15);
-
- // street address part
- $address[] = mt_rand(1, 150). ' '
- . self::$roads[array_rand(self::$roads)]. ' '
- . self::$road_suffix[array_rand(self::$road_suffix)];
-
- // town and county
- $county = array_rand(self::$places);
- $address[] = self::$places[$county][array_rand(self::$places[$county])];
- $address[] = $county;
-
- if( $postcode )
- $address[] = self::postcode();
-
- // ensure 5 elements
- while( count($address) < 5 )
- $address[] = '';
-
- return $address;
-
- } // address
-
- /**
- * Returns a randomly generated postcode.
- * Note: postcodes generated by this function are not guaranteed to actually exist.
- *
- * @return string
- */
- public static function postcode() {
-
- return chr(64 + mt_rand(1, 26))
- . chr(64 + mt_rand(1, 26))
- . mt_rand(10, 99)
- . ' '
- . mt_rand(1, 9)
- . chr(64 + mt_rand(1, 26))
- . chr(64 + mt_rand(1, 26));
-
- } // post_code
-
- /**
- * Returns a randomly generated phone number.
- * Note: the STD prefix or phone number generated are not guaranteed to exist.
- *
- * @return string
- */
- public static function phone() {
-
- return '0'. mt_rand(1111,1999). ' '. mt_rand(31, 99). mt_rand(1000, 9999);
-
- } // phone
-
- /**
- * Returns a randomly generated date.
- *
- * @param integer within number of years within the current year the date must be.
- * @param boolean time_stamp if true the value will be returned as an integer timestamp.
- * @return mixed
- */
- public static function date( $within = 100, $time_stamp = false ) {
-
- $year = (int) date('Y');
- $ts = mktime( mt_rand(0, 23), mt_rand(0, 59), mt_rand(0, 59), mt_rand(1, 12), mt_rand(1, 31), mt_rand($year - $within, $year) );
-
- if( !$time_stamp )
- $ts = date('Y-m-d H:i:s', $ts);
-
- return $ts;
-
- } // date
-
- /**
- * Returns a randomly generated job title.
- *
- * @return string
- */
- public static function job_title() {
-
- return self::$job_titles_1[array_rand(self::$job_titles_1)]. ' '
- . self::$job_titles_2[array_rand(self::$job_titles_2)]. ' '
- . self::$job_titles_3[array_rand(self::$job_titles_3)];
-
- } // job_title
-
- /**
- * Returns a block of randomly generated text.
- *
- * @param integer count number of paragraphs or words to generate.
- * @param boolean paragraphs if true paragraphs are generated; if false a single sentence is generated.
- * @return string
- */
- public static function lorem_ipsum( $count = 3, $paragraphs = true ) {
-
- $text = '';
-
- if( $paragraphs ) {
-
- for( $i = 0; $i < $count; $i++ ) {
-
- // sentences in this paragraph
- $sentences = mt_rand(3, 6);
-
- for( $j = 0; $j < $sentences; $j++ ) {
-
- // words in this sentence
- $words = mt_rand(3, 9);
-
- for( $k = 0; $k < $words; $k++ ) {
-
- $word = self::$lorem[array_rand(self::$lorem)];
-
- if( $k == 0 )
- $word = ucfirst($word);
-
- $text .= $word;
-
- if( $k < ($words - 1) )
- $text .= ' ';
-
- } // words
-
- $text .= '. ';
-
- } // sentences
-
- } // paragraphs
- }
- else {
-
- for( $i = 0; $i < $count; $i++ ) {
-
- $word = self::$lorem[array_rand(self::$lorem)];
-
- if( $i == 0 )
- $word = ucfirst($word);
-
- $text .= $word;
-
- if( $i < ($count - 1) )
- $text .= ' ';
-
- } // words
-
- $text .= '.';
-
- }
-
- return $text;
-
- } // lorem_ipsum
-
- } // SPF_Random
-
- ?>