PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/SPF_Random.php

http://spf-php.googlecode.com/
PHP | 353 lines | 198 code | 73 blank | 82 comment | 18 complexity | 4a7075bd07840688485ba2fa83385621 MD5 | raw file
  1. <?php
  2. /**
  3. * SPF_Random
  4. * @package spf
  5. * @author Simon Downes <simon@simondownes.co.uk>
  6. * @copyright Copyright (c) 2008, Simon Downes
  7. * @license http://www.opensource.org/licenses/mit-license.php
  8. */
  9. /**
  10. * Random data generator class.
  11. *
  12. * @package spf
  13. * @author Simon Downes <simon@simondownes.co.uk>
  14. * @copyright Copyright (c) 2008, Simon Downes
  15. * @license http://www.opensource.org/licenses/mit-license.php
  16. */
  17. final class SPF_Random {
  18. private static $boys = array(
  19. 'Aaron','Adam','Adrian','Aidan','Alan','Albert','Alexander','Andrew','Anthony','Arthur','Barry','Benjamin','Brian','Chandler',
  20. 'Charles','Chrisopher','Christian','Clarke','Claudius','Clive','Colin','Connor','Craig','Dale','Damien','Daniel','David',
  21. 'Declan','Derek','Dominic','Dylan','Edmund','Edward','Eric','Ethan','Evan','Fredrick','Gallahad','Gareth','Garth','Gary',
  22. 'Gavin','George','Gordon','Graham','Gregory','Harry','Hayden','Ian','Jack','James','Jason','Jeremy','Jonathan','Jordon',
  23. 'Joseph','Joshua','Julian','Justin','Kenneth','Kevin','Kyle','Kyle','Lancelot','Leonardo','Liam','Logan','Luke','Malcolm',
  24. 'Marcus','Mark','Matthew','Michael','Nathan','Neil','Nicholas','Nigel','Octavius','Odin','Oliver','Owen','Patrick','Paul',
  25. 'Pedro','Peter','Phillip','Richard','Robert','Roger','Ryan','Samuel','Scott','Sean','Shane','Simon','Steven','Terry',
  26. 'Thomas','Timothy','Tony','Trevor','William','Plebie'
  27. );
  28. private static $girls = array(
  29. 'Abigail', 'Adriana', 'Alexandra', 'Alexis', 'Allison', 'Alyssa', 'Amanda', 'Amber', 'Amelia', 'Angela', 'Anna', 'Anne', 'Ashley',
  30. 'Audrey', 'Brianna', 'Brooke', 'Carol', 'Caroline', 'Catherine', 'Chloe', 'Claire', 'Danielle', 'Dawn', 'Deborah', 'Diana',
  31. 'Diane', 'Dorothy', 'Elizabeth', 'Ella', 'Emily', 'Emma', 'Erin', 'Gabrielle', 'Gemma', 'Georgia', 'Grace', 'Haley', 'Hannah',
  32. 'Helen', 'Isabella', 'Isabelle', 'Jackie', 'Janet', 'Jasmine', 'Jenna', 'Jessica', 'Jordan', 'Judith', 'Julia', 'Kaitlyn',
  33. 'Katherine', 'Kayla', 'Kaylee', 'Kylie', 'Lauren', 'Lily', 'Louise', 'Madeline', 'Madison', 'Mandy', 'Marie', 'Marissa',
  34. 'Mary', 'Megan', 'Michelle', 'Nadia', 'Natalie', 'Nicole', 'Olivia', 'Paula', 'Rachel', 'Rebecca', 'Rose', 'Sabrina', 'Sally',
  35. 'Samantha', 'Sandra', 'Sarah', 'Sharon', 'Sophia', 'Stephanie', 'Sydney', 'Tabitha', 'Tanya', 'Vicky', 'Victoria', 'Zoe'
  36. );
  37. private static $surnames = array(
  38. 'Abbott', 'Adams', 'Ashton', 'Bacon', 'Baggio', 'Bailey', 'Baker', 'Bale', 'Barker', 'Barnbrook', 'Beckingham', 'Bedford', 'Bell',
  39. 'Black', 'Blackburn', 'Blackwell', 'Bradford', 'Brandon', 'Britten', 'Brooks', 'Brown', 'Burke', 'Butler', 'Butterworth',
  40. 'Byrne', 'Campbell', 'Carpenter', 'Carter', 'Clooney', 'Cole', 'Coleman', 'Collier', 'Cooper', 'Cottle', 'Crocker', 'Cross',
  41. 'Davis', 'Day', 'Dixon', 'Dobson', 'Dolman', 'Doyle', 'Eastwood', 'Edwards', 'Einstein', 'Everest', 'Fairbanks', 'Ferguson',
  42. 'Fields', 'Flynn', 'Ford', 'Frost', 'Furmanski', 'Garton', 'Gibbons', 'Golding', 'Goldsmith', 'Goodwin', 'Grant', 'Gray',
  43. 'Griffiths', 'Hall', 'Hamilton', 'Harris', 'Heston', 'Hill', 'Holdstock', 'Holmes', 'Hopper', 'Houghton', 'Howard', 'Hudson',
  44. 'Hunt', 'Hunter', 'Husband', 'Hutchinson', 'Ivory', 'Jefferies', 'Johnson', 'Jones', 'Knight', 'Lamprell', 'Larkin', 'Lewis',
  45. 'Littlejohn', 'Littlewood', 'Lowe', 'Maddison', 'Marshall', 'Martin', 'Mason', 'McFadyen', 'Mclaren', 'McPleb', 'Merricks',
  46. 'Middleton', 'Monk', 'Montoya', 'Moss', 'Murphy', 'Murray', 'Nash', 'Nelson', 'Newman', 'Newton', 'Nicholls', 'Norris',
  47. 'Oakley', 'O\'Connor', 'O\'Dell', 'O\'Donnell', 'O\'Neil', 'Parker', 'Parry', 'Parsons', 'Pearson', 'Perry', 'Pert', 'Philips',
  48. 'Piper', 'Powers', 'Pridmore', 'Proctor', 'Reeves', 'Richards', 'Riley', 'Roberts', 'Robertson', 'Robinson', 'Robson', 'Rogers',
  49. 'Sadler', 'Saunders', 'Scott', 'Sheppard', 'Shields', 'Shuttleworth', 'Simpson', 'Smith', 'Stagg', 'Stevens', 'Street',
  50. 'Taylor', 'Templeton', 'Thompson', 'Tucker', 'Turner', 'Vincent', 'Walker', 'Wallace', 'Walsh', 'Warner', 'Watson',
  51. 'Webb', 'Wenham', 'White', 'Whitehouse', 'Whittle', 'Wilkinson', 'Williams', 'Wilson', 'Young'
  52. );
  53. private static $roads = array(
  54. 'Addison', 'Albert', 'Alders', 'Austin', 'Baker', 'Bishops', 'Brunswick', 'Buckhurst', 'Buckingham', 'Charlwoods', 'Chester', 'Church',
  55. 'Clifton', 'Crossways', 'Edward', 'Elm', 'Farm', 'Garland', 'George', 'Goldstone', 'Green', 'Grove', 'Harvest', 'Harwoods', 'Heathcote',
  56. 'Herontye', 'Highfield', 'Imberhorne', 'Kennedy', 'Kings', 'Lansdowne', 'Livingstone', 'Lyndhurst', 'Manor', 'Maple', 'Mill',
  57. 'Morton', 'Oak', 'Orchard', 'Palm', 'Park', 'Portland', 'Queens', 'Regent', 'Richmond', 'Sackville', 'Sandhurst', 'Shakespeare',
  58. 'Somerset', 'Southlands', 'Springfield', 'Stanley', 'Station', 'Sycamore', 'Tenneson', 'Victoria', 'Westbourne', 'Willow',
  59. 'Windmill', 'Windsor', 'Woodbury', 'Wordsworth', 'York'
  60. );
  61. private static $road_suffix = array('Road','Avenue','Street','Close','Drive','Walk','Cresent','Hill','Lane','Parade','Way','Rise');
  62. private static $places = array(
  63. 'Bedfordshire' => array('Bedford', 'Luton', 'Dunstable', 'Leighton Buzzard', 'Biggleswade', 'Sandy'),
  64. 'Berkshire' => array('Reading', 'Bracknell', 'Maidenhead', 'Newbury', 'Windsor', 'Wokingham', 'Abingdon'),
  65. 'Buckinghamshire' => array('Aylesbury', 'Milton Keynes', 'Slough', 'Buckingham', 'High Wycombe'),
  66. 'Cambridgeshire' => array('Cambridge', 'Wisbech', 'Ely', 'March', 'Whittlesey', 'Chatteris', 'Linton'),
  67. 'Cheshire' => array('Chester', 'Stockport', 'Ellesmere Port', 'Birkenhead', 'Wallasey', 'Runcorn', 'Macclesfield', 'Crewe'),
  68. 'Cornwall' => array('Bodmin', 'Truro', 'Camborne', 'Redruth', 'St. Austell', 'Falmouth', 'Penzance', 'Newquay'),
  69. 'Cumberland' => array('Carlisle', 'Whitehaven', 'Workington', 'Penrith', 'Keswick', 'Brampton'),
  70. 'Derbyshire' => array('Derby', 'Chesterfield', 'Ilkeston', 'Swadlincote', 'Buxton', 'Matlock', 'Ashbourne'),
  71. 'Devon' => array('Exeter', 'Plymouth', 'Torquay', 'Paignton', 'Barnstaple', 'Tiverton', 'Newton Abbot', 'Tavistock'),
  72. 'Dorset' => array('Dorchester', 'Poole', 'Weymouth', 'Sherborne', 'Wimborne Minster', 'Shaftesbury'),
  73. 'Durham' => array('Durham', 'Sunderland', 'Stockton-on-Tees', 'Darlington', 'Hartlepool', 'Gateshead', 'Washington'),
  74. 'Essex' => array('Chelmsford', 'Basildon', 'Romford', 'Southend', 'Colcheter', 'Harlow', 'Brentwood', 'West Ham'),
  75. 'Gloucestershire' => array('Gloucester', 'Bristol', 'Cheltenham', 'Stroud', 'Cirencester', 'Tewkesbury'),
  76. 'Hampshire' => array('Winchester', 'Southampton', 'Portsmouth', 'Bournemouth', 'Basingstoke', 'Newport'),
  77. 'Herefordshire' => array('Hereford', 'Ross-on-Wye', 'Leominster', 'Ledbury', 'Bromyard', 'Kington'),
  78. 'Hertfordshire' => array('Hertford', 'Watford', 'St. Albans', 'Hemel Hempstead', 'Stevenage', 'Hatfield'),
  79. 'Huntingdonshire' => array('Huntingdon', 'St. Ives', 'St. Neots', 'Ramsey', 'Yaxley'),
  80. 'Kent' => array('Maidstone', 'Canterbury', 'Bromley', 'Rochester', 'Margate', 'Folkestone', 'Dover', 'Greenwich'),
  81. 'Lancashire' => array('Lancaster', 'Liverpool', 'Manchester', 'Preston', 'Bolton', 'Warrington', 'Barrow-in-Furness'),
  82. 'Leicestershire' => array('Leicester', 'Loughborough', 'Hinckley', 'Melton Mowbray', 'Coalville', 'Lutterworth'),
  83. 'Lincolnshire' => array('Lincoln', 'Grimsby', 'Scunthorpe', 'Boston', 'Grantham', 'Stamford', 'Skegness', 'Louth'),
  84. 'Middlesex' => array('City of London', 'Harrow', 'Enfield', 'Staines', 'Ealing', 'Potters Bar', 'Westminster '),
  85. 'Norfolk' => array('Norwich', 'Great Yarmouth', 'King\'s Lynn', 'Dereham', 'Cromer', 'Hunstanton'),
  86. 'Northamptonshire' => array('Northampton', 'Peterborough', 'Corby', 'Kettering', 'Wellingborough'),
  87. 'Northumberland' => array('Alnwick', 'Newcastle-upon-Tyne', 'Morpeth', 'Hexham', 'Berwick-upon-Tweed'),
  88. 'Nottinghamshire' => array('Nottingham', 'Mansfield', 'Worksop', 'Newark', 'Retford', 'Southwell'),
  89. 'Oxfordshire' => array('Oxford', 'Banbury', 'Witney', 'Bicester', 'Henley-on-Thames', 'Carterton', 'Thame'),
  90. 'Rutland' => array('Oakham', 'Uppingham. Cottesmore'),
  91. 'Shropshire' => array('Shrewsbury', 'Telford', 'Oswestry', 'Bridgnorth', 'Whitchurch', 'Market Drayton', 'Ludlow'),
  92. 'Somerset' => array('Taunton', 'Bath', 'Weston-super-Mare', 'Yeovil', 'Bridgwater', 'Wells', 'Glastonbury'),
  93. 'Staffordshire' => array('Stafford', 'Stoke-on-Trent', 'Wolverhampton', 'Walsall', 'Cannock', 'Lichfield'),
  94. 'Suffolk' => array('Ipswich', 'Bury St. Edmunds', 'Lowestoft', 'Felixstowe', 'Sudbury', 'Haverhill', 'Bungay'),
  95. 'Surrey' => array('Guildford', 'Croydon', 'Woking', 'Sutton', 'Kingston-on-Thames', 'Wandsworth', 'Wimbledon', 'Brixton'),
  96. 'Sussex' => array('Chichester', 'Brighton', 'Worthing', 'Crawley', 'Hastings', 'Eastbourne', 'Bognor Regis', 'Horsham'),
  97. 'Warwickshire' => array('Warwick', 'Birmingham', 'Coventry', 'Nuneaton', 'Rugby', 'Solihull', 'Stratford-upon-Avon'),
  98. 'Westmorland' => array('Appleby', 'Kendal', 'Windermere', 'Ambleside', 'Kirkby Lonsdale'),
  99. 'Wiltshire' => array('Trowbridge', 'Salisbury', 'Swindon', 'Chippenham', 'Devizes', 'Marlborough', 'Warminster'),
  100. 'Worcestershire' => array('Worcester', 'Dudley', 'Kidderminster', 'Stourbridge', 'Halesowen', 'Malvern', 'Evesham'),
  101. 'North Yorkshire' => array('Northallerton', 'Middlesbrough', 'Scarborough', 'Whitby'),
  102. 'East Yorkshire' => array('Beverley', 'Hull', 'Bridlington', 'Driffield', 'Hornsea', 'Filey'),
  103. 'West Yorkshire' => array('Wakefield', 'Leeds', 'Sheffield', 'Bradford', 'Halifax', 'Harrogate')
  104. ); // places
  105. 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');
  106. 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');
  107. private static $job_titles_3 = array('Pleb','Manager','Engineer','Specialist','Director','Coordinator','Administrator','Architect','Analyst','Designer','Planner','Orchestrator','Technician','Developer','Producer','Consultant','Assistant','Facilitator');
  108. private static $lorem = array(
  109. 'a','ac','accumsan','ad','adipiscing','aenean','aliquam','aliquet','amet','ante','aptent','arcu','at','auctor','augue',
  110. 'bibendum','blandit','class','commodo','condimentum','congue','consectetuer','consequat','conubia','convallis','cras','cubilia',
  111. 'cum','curabitur','curae;','cursus','dapibus','diam','dictum','dictumst','dignissim','dis','dolor','donec','dui','duis','egestas',
  112. 'eget','eleifend','elementum','elit','enim','erat','eros','est','et','etiam','eu','euismod','facilisi','facilisis','fames',
  113. 'faucibus','felis','fermentum','feugiat','fringilla','fusce','gravida','habitant','habitasse','hac','hendrerit','hymenaeos',
  114. 'iaculis','id','imperdiet','in','inceptos','integer','interdum','ipsum','justo','lacinia','lacus','laoreet','lectus','leo','libero',
  115. 'ligula','litora','lobortis','lorem','luctus','maecenas','magna','magnis','malesuada','massa','mattis','mauris','metus','mi',
  116. 'molestie','mollis','montes','morbi','mus','nam','nascetur','natoque','nec','neque','netus','nibh','nisi','nisl','non','nonummy',
  117. 'nostra','nulla','nullam','nunc','odio','orci','ornare','parturient','pede','pellentesque','penatibus','per','pharetra','phasellus',
  118. 'placerat','platea','porta','porttitor','posuere','potenti','praesent','pretium','primis','proin','pulvinar','purus','quam','quis',
  119. 'quisque','rhoncus','ridiculus','risus','rutrum','sagittis','sapien','scelerisque','sed','sem','semper','senectus','sit','sociis',
  120. 'sociosqu','sodales','sollicitudin','suscipit','suspendisse','taciti','tellus','tempor','tempus','tincidunt','torquent','tortor',
  121. 'tristique','turpis','ullamcorper','ultrices','ultricies','urna','ut','varius','vehicula','vel','velit','venenatis','vestibulum',
  122. 'vitae','vivamus','viverra','volutpat','vulputate'
  123. );
  124. /**
  125. * Cannot be instantiated.
  126. *
  127. * @return void
  128. */
  129. private function __construct() {
  130. } // __construct
  131. /**
  132. * Returns a randomly generated first name.
  133. *
  134. * @param mixed gender false for a girls name, true for a boys name, not-specified for a random gender.
  135. * @return string
  136. */
  137. public static function forename( $gender = NULL ) {
  138. if( $gender === NULL )
  139. $gender = mt_rand(0, 1);
  140. if( $gender )
  141. return self::$boys[array_rand(self::$boys)];
  142. else
  143. return self::$girls[array_rand(self::$girls)];
  144. } // forename
  145. /**
  146. * Returns a randomly generated surname.
  147. *
  148. * @return string
  149. */
  150. public static function surname() {
  151. return self::$surnames[array_rand(self::$surnames)];
  152. } // surname
  153. /**
  154. * Returns a randomly generated full name.
  155. *
  156. * @param mixed gender false for a girls name, true for a boys name, not-specified for a random gender.
  157. * @return string
  158. */
  159. public static function name( $gender = NULL ) {
  160. return self::forename($gender). ' '. self::surname();
  161. } // name
  162. /**
  163. * Returns a randomly generated address.
  164. * The address is returned as a zero-based array of five elements. At least three elements
  165. * of the array will be filled and empty elements (if any) will appear at the end of the array.
  166. *
  167. * @param boolean postcode if true a postcode will be included in the returned array.
  168. * @return array
  169. */
  170. public static function address( $postcode = false ) {
  171. $address = array();
  172. // 1 in 5 addresses will be flats (on average)
  173. if( mt_rand(1, 5) == 3 )
  174. $address[] = 'Flat '. mt_rand(1, 15);
  175. // street address part
  176. $address[] = mt_rand(1, 150). ' '
  177. . self::$roads[array_rand(self::$roads)]. ' '
  178. . self::$road_suffix[array_rand(self::$road_suffix)];
  179. // town and county
  180. $county = array_rand(self::$places);
  181. $address[] = self::$places[$county][array_rand(self::$places[$county])];
  182. $address[] = $county;
  183. if( $postcode )
  184. $address[] = self::postcode();
  185. // ensure 5 elements
  186. while( count($address) < 5 )
  187. $address[] = '';
  188. return $address;
  189. } // address
  190. /**
  191. * Returns a randomly generated postcode.
  192. * Note: postcodes generated by this function are not guaranteed to actually exist.
  193. *
  194. * @return string
  195. */
  196. public static function postcode() {
  197. return chr(64 + mt_rand(1, 26))
  198. . chr(64 + mt_rand(1, 26))
  199. . mt_rand(10, 99)
  200. . ' '
  201. . mt_rand(1, 9)
  202. . chr(64 + mt_rand(1, 26))
  203. . chr(64 + mt_rand(1, 26));
  204. } // post_code
  205. /**
  206. * Returns a randomly generated phone number.
  207. * Note: the STD prefix or phone number generated are not guaranteed to exist.
  208. *
  209. * @return string
  210. */
  211. public static function phone() {
  212. return '0'. mt_rand(1111,1999). ' '. mt_rand(31, 99). mt_rand(1000, 9999);
  213. } // phone
  214. /**
  215. * Returns a randomly generated date.
  216. *
  217. * @param integer within number of years within the current year the date must be.
  218. * @param boolean time_stamp if true the value will be returned as an integer timestamp.
  219. * @return mixed
  220. */
  221. public static function date( $within = 100, $time_stamp = false ) {
  222. $year = (int) date('Y');
  223. $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) );
  224. if( !$time_stamp )
  225. $ts = date('Y-m-d H:i:s', $ts);
  226. return $ts;
  227. } // date
  228. /**
  229. * Returns a randomly generated job title.
  230. *
  231. * @return string
  232. */
  233. public static function job_title() {
  234. return self::$job_titles_1[array_rand(self::$job_titles_1)]. ' '
  235. . self::$job_titles_2[array_rand(self::$job_titles_2)]. ' '
  236. . self::$job_titles_3[array_rand(self::$job_titles_3)];
  237. } // job_title
  238. /**
  239. * Returns a block of randomly generated text.
  240. *
  241. * @param integer count number of paragraphs or words to generate.
  242. * @param boolean paragraphs if true paragraphs are generated; if false a single sentence is generated.
  243. * @return string
  244. */
  245. public static function lorem_ipsum( $count = 3, $paragraphs = true ) {
  246. $text = '';
  247. if( $paragraphs ) {
  248. for( $i = 0; $i < $count; $i++ ) {
  249. // sentences in this paragraph
  250. $sentences = mt_rand(3, 6);
  251. for( $j = 0; $j < $sentences; $j++ ) {
  252. // words in this sentence
  253. $words = mt_rand(3, 9);
  254. for( $k = 0; $k < $words; $k++ ) {
  255. $word = self::$lorem[array_rand(self::$lorem)];
  256. if( $k == 0 )
  257. $word = ucfirst($word);
  258. $text .= $word;
  259. if( $k < ($words - 1) )
  260. $text .= ' ';
  261. } // words
  262. $text .= '. ';
  263. } // sentences
  264. } // paragraphs
  265. }
  266. else {
  267. for( $i = 0; $i < $count; $i++ ) {
  268. $word = self::$lorem[array_rand(self::$lorem)];
  269. if( $i == 0 )
  270. $word = ucfirst($word);
  271. $text .= $word;
  272. if( $i < ($count - 1) )
  273. $text .= ' ';
  274. } // words
  275. $text .= '.';
  276. }
  277. return $text;
  278. } // lorem_ipsum
  279. } // SPF_Random
  280. ?>