Skip to content

Commit

Permalink
✨ 新增邮箱号生成器
Browse files Browse the repository at this point in the history
  • Loading branch information
Redns committed Jun 8, 2022
1 parent 253a120 commit 59afa01
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/CreditCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static IEnumerable<string> Generate(BinType binType = BinType.Any, int le
{
var fakeCardNumber = 0L;
var fakeCardNumbers = new string[count];
var r = new Random(DateTime.Now.Second + DateTime.Now.Millisecond);
var r = new Random(DateTime.Now.Second * 1000 + DateTime.Now.Millisecond);

for (int i = 0; i < count; i++)
{
Expand Down
41 changes: 41 additions & 0 deletions lib/Email.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace FakeSharp
{
public class Email
{
static readonly string[] EMAIL_SUFFIX = { "163.com", "qq.com", "126.com", "139.com", "gmail.com", "yahoo.com", "msn.com",
"hotmail.com", "aol.com", "ask.com", "live.com", "outlook.com", "163.net" };
static readonly char[] LEGAL_CHARACTER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

public static IEnumerable<string> Generate(string[]? emailSuffix = null, int minLength = 8, int maxLength = 8, int count = 100)
{
// 检验输入参数
if(emailSuffix == null) { emailSuffix = EMAIL_SUFFIX; }
if(minLength <= 0) { minLength = 8; }
if(maxLength <= 0) { maxLength = 8; }
if(minLength > maxLength) { minLength = maxLength; }
if(count <= 0) { count = 100; }

var fakeEmails = new string[count];
var random = new Random(DateTime.Now.Second * 1000 + DateTime.Now.Millisecond);

// 48-57:数字0~9
// 65-90:大写字母A~Z
// 97-122:小写字母a~z
// 95:下划线
for(int i = 0; i < count; i++)
{
fakeEmails[i] = string.Empty;
for(int j = 0; j < random.Next(minLength, maxLength + 1); j++)
{
fakeEmails[i] += LEGAL_CHARACTER[random.Next(LEGAL_CHARACTER.Length)];
}
fakeEmails[i] += $"@{emailSuffix[random.Next(emailSuffix.Length)]}";
}

return fakeEmails;
}
}
}
4 changes: 2 additions & 2 deletions lib/FakeSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageTags>data-generation</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>✨ 新增身份证号生成器</PackageReleaseNotes>
<PackageReleaseNotes>✨ 新增邮箱号生成器</PackageReleaseNotes>
<Description>伪数据生成器,用于构造手机号、银行卡号、身份证号等数据</Description>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion lib/MobileNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MobileNumber
/// <returns></returns>
public static IEnumerable<string> Generate(MAC macConfig = MAC.Any, int count = 100)
{
var r = new Random(DateTime.Now.Second + DateTime.Now.Millisecond);
var r = new Random(DateTime.Now.Second * 1000 + DateTime.Now.Millisecond);
var fakeNumbers = new string[count];
for(int i = 0; i < count; i++)
{
Expand Down
17 changes: 17 additions & 0 deletions test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ static void Main(string[] args)

// 随机生成10个身份证号
GenerateIDCardNumbers();

// 随机生成10个邮箱账号
GenerateEmails();
}

/// <summary>
Expand Down Expand Up @@ -59,5 +62,19 @@ static void GenerateIDCardNumbers()
Console.WriteLine($"[{i}]{fakeIDCardNumbers[i]}");
}
}

/// <summary>
/// 随机生成邮箱号
/// </summary>
static void GenerateEmails()
{
var fakeEmails = Email.Generate(count: 10).ToArray();

Console.WriteLine("########## 邮箱号 ##########");
for (int i = 0; i < fakeEmails.Length; i++)
{
Console.WriteLine($"[{i}]{fakeEmails[i]}");
}
}
}
}

0 comments on commit 59afa01

Please sign in to comment.