Inital commit with most of the completed code
This commit is contained in:
91
DataGenerator.pas
Normal file
91
DataGenerator.pas
Normal file
@@ -0,0 +1,91 @@
|
||||
unit DataGenerator;
|
||||
|
||||
interface
|
||||
uses
|
||||
System.Math,
|
||||
System.SysUtils;
|
||||
|
||||
type
|
||||
TDataGenerator = class
|
||||
private
|
||||
var FSeed: Integer;
|
||||
var FEmailDomains: TArray<string>;
|
||||
|
||||
function GenerateRandomString(ALength:Integer): string;
|
||||
public
|
||||
constructor Create(seed:Integer);
|
||||
destructor Destroy; override;
|
||||
|
||||
function GenerateRandomEmail: string;
|
||||
function GenerateRandomAge: Integer;
|
||||
function GenerateRandomSocial: string;
|
||||
|
||||
end;
|
||||
implementation
|
||||
constructor TDataGenerator.Create(seed: Integer);
|
||||
begin
|
||||
FSeed := seed;
|
||||
RandSeed := FSeed;
|
||||
FEmailDomains := ['@proton.me',
|
||||
'@protonmail.com',
|
||||
'@gmail.com',
|
||||
'@outlook.com',
|
||||
'@live.kutztown.edu',
|
||||
'@kutztown.edu',
|
||||
'@hotmail.com',
|
||||
'@yahoo.com',
|
||||
'@aol.com'];
|
||||
|
||||
|
||||
end;
|
||||
|
||||
destructor TDataGenerator.Destroy;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function TDataGenerator.GenerateRandomString(ALength: Integer): string;
|
||||
begin
|
||||
const
|
||||
AllowedChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
||||
var
|
||||
LIndex: Integer;
|
||||
|
||||
SetLength(Result, ALength);
|
||||
|
||||
for LIndex := 1 to ALength do
|
||||
begin
|
||||
Result[LIndex] := AllowedChars[Random(Length(AllowedChars)) + 1];
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDataGenerator.GenerateRandomEmail: string;
|
||||
begin
|
||||
|
||||
var LDomain: string;
|
||||
var LDomainIndex: Integer;
|
||||
LDomainIndex := RandomRange(0, Length(FEmailDomains));
|
||||
LDomain := FEmailDomains[LDomainIndex];
|
||||
|
||||
Result := GenerateRandomString(32) + LDomain;
|
||||
end;
|
||||
|
||||
function TDataGenerator.GenerateRandomSocial: string;
|
||||
begin
|
||||
var LFirstThree: Integer;
|
||||
var LMiddleTwo: Integer;
|
||||
var LLastThree: Integer;
|
||||
|
||||
LFirstThree := RandomRange(100, 1000);
|
||||
LMiddleTwo := RandomRange(10, 100);
|
||||
LLastThree := RandomRange(100, 1000);
|
||||
Result := '';
|
||||
Result := LFirstThree.ToString + '-' + LMiddleTwo.ToString + '-' + LLastThree.ToString;
|
||||
end;
|
||||
|
||||
function TDataGenerator.GenerateRandomAge: Integer;
|
||||
begin
|
||||
Result := RandomRange(1, 102);
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user