spf-php /SPF_Random.php

Language PHP Lines 354
MD5 Hash 4a7075bd07840688485ba2fa83385621 Estimated Cost $4,881 (why?)
Repository http://spf-php.googlecode.com/svn/trunk/ View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?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

?>
Back to Top