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
|
{
fpGUI - Free Pascal GUI Toolkit
Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Description:
This unit allows you to generate random data. This is very handy
for testing purposes.
This code originates from the InstantObjects project, but has been
adapted for our needs.
}
unit RandomData;
{$mode objfpc}{$H+}
interface
type
TGender = (gnMale, gnFemale);
function RandomName: string;
function RandomCompanyName: string;
function RandomEmail(const PersonName, DomainName: string): string;
function RandomFirstName(Gender: TGender): string;
function RandomFullName(Gender: TGender): string;
function RandomLastName: string;
function RandomNumber(Len: Integer): string;
function RandomStreet: string;
function RandomCity: string;
implementation
uses
SysUtils;
const
Letters = ['a'..'z'];
Vowels = ['a', 'e', 'i', 'o', 'u', 'y'];
Consonants = Letters - Vowels;
SmartPrefixes: array[0..19] of string = (
'cor', 'pri', 'pre', 'neo', 'new', 'or', 'hi', 'inter',
'u', 'i', 'core', 'xo', 'xe', 'xor', 'xer', 'qua', 'gen',
'in', 're', 'tri');
SmartSuffixes: array[0..12] of string = (
'teq', 'tex', 'tec', 'nix', 'lix', 'tor', 'max', 'time', 'qua',
'paq', 'pac', 'nic', 'nec');
FirstNames: array[TGender, 0..33] of string = ((
'Anthony', 'Brian', 'Charles', 'Christopher', 'Daniel', 'David', 'Donald',
'Edward', 'George', 'James', 'Jason', 'Jeff', 'John', 'Joseph', 'Kenneth',
'Kevin', 'Mark', 'Michael', 'Paul', 'Richard', 'Robert', 'Ronald', 'Steven',
'Thomas', 'William', 'Graeme', 'Jaco', 'Martin', 'Sam', 'Dale', 'Johan',
'Zayn', 'Xiam', 'René'), (
'Barbara', 'Betty', 'Carol', 'Deborah', 'Donna', 'Dorothy', 'Elizabeth',
'Helen', 'Jennifer', 'Karen', 'Kimberly', 'Laura', 'Linda', 'Lisa',
'Margaret', 'Maria', 'Mary', 'Michelle', 'Nancy', 'Patricia', 'Ruth',
'Sandra', 'Sarah', 'Sharon', 'Susan', 'Debbie', 'Anthea', 'Theonette',
'Amelia', 'Adrie', 'Petro', 'Yolanda', 'Zelda', 'René'));
LastNames: array[0..53] of string = (
'Adams', 'Allen', 'Anderson', 'Baker', 'Brown', 'Campbell', 'Carter',
'Clark', 'Collins', 'Davis', 'Edwards', 'Evans', 'Garcia', 'Gonzalez',
'Green', 'Hall', 'Harris', 'Hernandez', 'Hill', 'Jackson', 'Johnson',
'Jones', 'King', 'Lee', 'Lewis', 'Lopez', 'Martin', 'Martinez', 'Miller',
'Mitchell', 'Moore', 'Nelson', 'Parker', 'Perez', 'Phillips', 'Roberts',
'Robinson', 'Rodriguez', 'Scott', 'Smith', 'Taylor', 'Thomas', 'Thompson',
'Turner', 'Walker', 'White', 'Williams', 'Wilson', 'Wright', 'Young',
'Geldenhuys', 'Welgens', 'Botha', 'Guthrie');
Adjectives: array[0..19] of string = (
'Intelligent', 'Smart', 'Wise', 'Bright', 'Essential', 'Basic', 'Happy',
'Precise', 'Fast', 'Express', 'Simple', 'Good', 'Deluxe', 'Perfect',
'Star', 'Future', 'Millenium', 'Solid', 'Sure', 'Great');
CompanySuffixes: array[0..19] of string = (
'Computers', 'Computing', 'Software', 'Technologies', 'Consulting', 'Food',
'Furniture', 'Textiles', 'Wear', 'Toys', 'Adventures', 'Services', 'Tools',
'Accessories', 'Entertainment', 'Flowers', 'Equipment', 'Items',
'Architecture', 'Knowledge');
CompanyTypes: array[0..2] of string = (
'Corp.', 'Inc.', 'Ltd.');
StreetPrefixes: array[0..3] of string = (
'North', 'East', 'South', 'West');
StreetBeginnings: array[0..16] of string = (
'Salt', 'Sun', 'Moon', 'Stone', 'Rock', 'Clear', 'White', 'Green',
'Corn', 'Shore', 'Cotton', 'Oak', 'Water', 'Bright', 'New', 'Old',
'Apple');
StreetEndings: array[0..6] of string = (
'wood', 'dale', 'land', 'bridge', 'lake', 'hill', 'field');
StreetTypes: array[0..7] of string = (
'Street', 'Road', 'Avenue', 'Place', 'Court', 'Boulevard', 'Drive',
'Parkway');
Cities: array[0..36] of string = (
'Alabama', 'Atlanta', 'Boston', 'Chicago', 'Cincinnati', 'Dallas', 'Denver',
'Detroit', 'Houston', 'Indianapolis', 'Kansas City', 'Las Vegas',
'Los Angeles', 'Memphis', 'Miami', 'Minneapolis', 'Nashville',
'New Orleans', 'New York', 'Oklahoma', 'Omaha', 'Philadelphia',
'Pittsburgh', 'Portland', 'San Diego', 'San Fransisco', 'Seattle', 'Tampa',
'Utah', 'Washington', 'Somerset West', 'Cape Town', 'Bloemfontein',
'Durban', 'Pretoria', 'London', 'Paris');
DomainSuffixes: array[0..6] of string = (
'com', 'org', 'net', 'edu', 'gov', 'co.za', 'co.uk');
function RandomStr(List: array of string): string;
begin
Result := List[Random(Length(List))];
end;
function RandomLetter: Char;
begin
Result := Chr(Ord('a') + Random(Ord('z') - Ord('a')));
end;
function RandomConsonant: Char;
begin
repeat
Result := RandomLetter;
until Result in Consonants;
end;
function RandomVowel: Char;
begin
repeat
Result := RandomLetter;
until Result in Vowels;
end;
function RandomName: string;
function SmartName: string;
begin
Result := RandomStr(SmartPrefixes) + RandomStr(SmartSuffixes);
end;
function CombiName: string;
begin
Result := RandomConsonant + RandomVowel;
if Odd(Random(2)) then
Result := Result + RandomConsonant;
Result := Result + RandomStr(SmartSuffixes);
end;
function TripletName: string;
var
I: Integer;
begin
Result := '';
for I := 1 to 3 do
begin
Result := Result + RandomConsonant + RandomVowel;
if Random(10) = 1 then
Result := Result + RandomConsonant;
end;
end;
begin
case Random(3) of
0: Result := SmartName;
1: Result := CombiName;
2: Result := TripletName;
end;
Result[1] := UpCase(Result[1]);
end;
function RandomCompanyName: string;
begin
if Random(3) = 0 then
Result := RandomStr(Adjectives)
else
Result := RandomName;
Result := Result + ' ' + RandomStr(CompanySuffixes) + ' ' +
RandomStr(CompanyTypes);
end;
function RandomEmail(const PersonName, DomainName: string): string;
var
Name, FirstName, LastName, Suffix: string;
I: Integer;
begin
I := Pos(' ', PersonName);
if I > 0 then
begin
FirstName := Copy(PersonName, 1, Pred(I));
LastName := PersonName;
Delete(LastName, 1, I);
end else
begin
FirstName := PersonName;
LastName := '';
end;
case Random(3) of
0: Name := FirstName + '.' + LastName;
1: Name := Copy(FirstName, 1, 1) + Copy(LastName, 1, 1);
2: Name := Copy(FirstName, 1, 1) + '_' + LastName;
end;
if Random(10) <> 0 then // 9 of 10 have .com
Suffix := DomainSuffixes[0] else
Suffix := RandomStr(DomainSuffixes);
Result := LowerCase(Name + '@' + DomainName + '.' + Suffix);
end;
function RandomFirstName(Gender: TGender): string;
begin
Result := FirstNames[Gender, Random(Length(FirstNames[gnMale]))];
end;
function RandomFullName(Gender: TGender): string;
begin
Result := RandomFirstName(Gender) + ' ' + RandomLastName;
end;
function RandomLastName: string;
begin
Result := RandomStr(LastNames);
end;
function RandomNumber(Len: Integer): string;
begin
Result := '';
while Len > 0 do
begin
Result := Result + Chr(Ord('0') + Random(10));
Dec(Len);
end;
end;
function RandomStreet: string;
begin
if Random(8) = 0 then
Result := RandomStr(StreetPrefixes) + ' '
else
Result := '';
Result := Result
+ RandomStr(StreetBeginnings)
+ RandomStr(StreetEndings) + ' '
+ RandomStr(StreetTypes) + ' '
+ IntToStr((Random(499) + 1) div (Random(9) + 1) + 1);
end;
function RandomCity: string;
begin
Result := RandomStr(Cities);
end;
end.
|