From 59afa01c07263fd6df17657e66c2de3b7ec30f80 Mon Sep 17 00:00:00 2001 From: Redns Date: Wed, 8 Jun 2022 22:23:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E5=8F=B7=E7=94=9F=E6=88=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/CreditCard.cs | 2 +- lib/Email.cs | 41 +++++++++++++++++++++++++++++++++++++++++ lib/FakeSharp.csproj | 4 ++-- lib/MobileNumber.cs | 2 +- test/Program.cs | 17 +++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 lib/Email.cs diff --git a/lib/CreditCard.cs b/lib/CreditCard.cs index c9d8b3a..d7b911c 100644 --- a/lib/CreditCard.cs +++ b/lib/CreditCard.cs @@ -34,7 +34,7 @@ public static IEnumerable 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++) { diff --git a/lib/Email.cs b/lib/Email.cs new file mode 100644 index 0000000..9673a01 --- /dev/null +++ b/lib/Email.cs @@ -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 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; + } + } +} diff --git a/lib/FakeSharp.csproj b/lib/FakeSharp.csproj index edc5150..4d86bd5 100644 --- a/lib/FakeSharp.csproj +++ b/lib/FakeSharp.csproj @@ -16,9 +16,9 @@ True data-generation MIT - ✨ 新增身份证号生成器 + ✨ 新增邮箱号生成器 伪数据生成器,用于构造手机号、银行卡号、身份证号等数据 - 1.0.4 + 1.0.5 diff --git a/lib/MobileNumber.cs b/lib/MobileNumber.cs index f7d9d73..782cf9e 100644 --- a/lib/MobileNumber.cs +++ b/lib/MobileNumber.cs @@ -19,7 +19,7 @@ public class MobileNumber /// public static IEnumerable 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++) { diff --git a/test/Program.cs b/test/Program.cs index 81a9b95..a55c027 100644 --- a/test/Program.cs +++ b/test/Program.cs @@ -14,6 +14,9 @@ static void Main(string[] args) // 随机生成10个身份证号 GenerateIDCardNumbers(); + + // 随机生成10个邮箱账号 + GenerateEmails(); } /// @@ -59,5 +62,19 @@ static void GenerateIDCardNumbers() Console.WriteLine($"[{i}]{fakeIDCardNumbers[i]}"); } } + + /// + /// 随机生成邮箱号 + /// + 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]}"); + } + } } } \ No newline at end of file