ダミーの個人情報を考えて入力するのが面倒くさいから、生成ツールを作った

件名の件、いちいち考えるのも入力するのも手間だったので、ヘルパークラスを作成しました。

目次

要求

というほどのことでもないのですが、適当な値で良いレベルで生成できればいいかなという前提です。もしも、ちゃんとしたそれらしいレベルであれば、ググれば素敵なウェブサービスがありますので、そちらを利用すればいいと思います。

使い方と出力結果

例えば、個別に項目を設定したい場合はこんな感じ。FakeData名前空間Personはクラスです。

C#

var name = FakeData.Person.NextName();
var age = FakeData.Person.NextAge();

VB.NET

Dim name As String = FakeData.Person.NextName()
Dim age As Integer = FakeData.Person.NextAge()

例えば、数件一気に生成して使いたい場合はこんな感じ。

C#

var persons = FakeData.Person.Generate(3);
foreach(var person in persons)
{
    Console.WriteLine($"名前: {person.Name}");
    Console.WriteLine($"年齢: {person.Age}");
}

VB.NET

Dim persons As IEnumerable(Of FakeData.FakePerson) = FakeData.Person.Generate(3)

For Each person As FakeData.FakePerson In persons

    Console.WriteLine($"名前: {person.Name}")
    Console.WriteLine($"年齢: {person.Age}")

Next

で、出力結果(というか扱いたい項目)はこんな感じ。

単体項目で呼び出した場合:

名前     : 太郎34
苗字     : サンプル
フルネーム  : サンプル 太郎69
年齢     : 29
性別     : True
メールアドレス: oss4e3mm@sample.com
パスワード  : b_v8oq4xmR5J
住所     : 新潟県テスト市サンプル123
電話番号1  : 080
電話番号2  : 2206
電話番号3  : 1924
電話番号   : 080-5745-6586

名前     : 太郎27
苗字     : サンプル
フルネーム  : サンプル 太郎9
年齢     : 68
性別     : False
メールアドレス: vc5rd1mq@sample.com
パスワード  : yyotRyz7L_Hq
住所     : 滋賀県テスト市サンプル123
電話番号1  : 080
電話番号2  : 9398
電話番号3  : 4041
電話番号   : 090-6524-8887

名前     : 太郎86
苗字     : サンプル
フルネーム  : サンプル 太郎56
年齢     : 64
性別     : True
メールアドレス: zbyp2yqx@sample.com
パスワード  : nmlUcnNOwECf
住所     : 新潟県テスト市サンプル123
電話番号1  : 080
電話番号2  : 7961
電話番号3  : 7382
電話番号   : 080-8760-0912

まとまりで呼び出した場合:

名前     : 太郎1
苗字     : サンプル
フルネーム  : サンプル 太郎1
年齢     : 22
性別     : True
メールアドレス: gk83a4e-@sample.com
パスワード  : dbaVrCfAZ4Xc
住所     : 長野県テスト市サンプル123
電話番号1  : 090
電話番号2  : 0541
電話番号3  : 5378
電話番号   : 090-0541-5378

名前     : 太郎2
苗字     : サンプル
フルネーム  : サンプル 太郎2
年齢     : 43
性別     : True
メールアドレス: ph-2gt8z@sample.com
パスワード  : qgO1EWi-JoZ0
住所     : 富山県テスト市サンプル123
電話番号1  : 080
電話番号2  : 3257
電話番号3  : 6260
電話番号   : 080-3257-6260

名前     : 太郎3
苗字     : サンプル
フルネーム  : サンプル 太郎3
年齢     : 35
性別     : True
メールアドレス: vtaxk424@sample.com
パスワード  : RZU6bWRwMwDl
住所     : 福岡県テスト市サンプル123
電話番号1  : 090
電話番号2  : 0718
電話番号3  : 5710
電話番号   : 090-0718-5710

C# のソース

ヘルパークラス

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FakeData
{
    public class Person
    {
        private static Random rnd = new Random();

        public static IEnumerable<FakePerson> Generate(uint count = 1)
        {
            if (count <= 0)
                throw new ArgumentException("生成数は 1 以上指定してください。");
            
            for (var i = 0; i < count; i++)
            {
                yield return new FakePerson
                {
                    Name = $"太郎{i + 1}",
                    FamilyName = NextFamilyName(),
                    Age = NextAge(),
                    IsMale = NextIsMale(),
                    MailAddress = NextMailAddress(),
                    Password = NextPassword(),
                    Address = NextAddress(),
                    Tel1 = NextTel1(),
                    Tel2 = NextTel2(),
                    Tel3 = NextTel3(),
                };
            }
        }

        public static string NextName() => $"太郎{rnd.Next(1, 100)}";
        public static string NextFamilyName() => "サンプル";
        public static string NextFullName() => $"{NextFamilyName()} {NextName()}";
        public static int NextAge() => rnd.Next(20, 81);
        public static bool NextIsMale() => rnd.Next() % 2 == 0 ? true : false;
        public static string NextMailAddress() => $"{RandomMail(8)}@sample.com";
        public static string NextPassword() => RandomPassword(12);
        public static string NextAddress() => RandomAddress();
        public static string NextTel1() => rnd.Next() % 2 == 0 ? "080" : "090";
        public static string NextTel2() => RandomTel(4);
        public static string NextTel3() => RandomTel(4);
        public static string NextTel() => $"{NextTel1()}-{NextTel2()}-{NextTel3()}";

        private static string RandomMail(int length)
        {
            var sb = new StringBuilder();
            var pwWords = "_-0123456789abcdefghijklmnopqrstuvwxyz";

            // 最初の 1 文字目は文字列固定
            var index = rnd.Next(12, pwWords.Length);
            sb.Append(pwWords[index]);

            for (var i = 0; i < length - 1; i++)
            {
                index = rnd.Next(pwWords.Length);
                sb.Append(pwWords[index]);
            }
            return sb.ToString();
        }

        private static string RandomPassword(int length)
        {
            var sb = new StringBuilder();
            var pwWords = "_-0123456789abcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyz".ToUpper();

            // 最初の 1 文字目は文字列固定
            var index = rnd.Next(12, pwWords.Length);
            sb.Append(pwWords[index]);

            for (var i = 0; i < length - 1; i++)
            {
                index = rnd.Next(pwWords.Length);
                sb.Append(pwWords[index]);
            }
            return sb.ToString();
        }

        private static string RandomAddress()
        {
            var pwWords = new List<string>() { "北海道", "青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県", "茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県", "新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県", "静岡県", "愛知県", "三重県", "滋賀県", "京都府", "大阪府", "兵庫県", "奈良県", "和歌山県", "鳥取県", "島根県", "岡山県", "広島県", "山口県", "徳島県", "香川県", "愛媛県", "高知県", "福岡県", "佐賀県", "長崎県", "熊本県", "大分県", "宮崎県", "鹿児島県", "沖縄県" };
            return $"{pwWords[rnd.Next(pwWords.Count)]}テスト市サンプル123";
        }

        private static string RandomTel(int length = 4)
        {
            var sb = new StringBuilder();
            var pwWords = "0123456789";
            
            for (var i = 0; i < length; i++)
            {
                var index = rnd.Next(pwWords.Length);
                sb.Append(pwWords[index]);
            }
            return sb.ToString();
        }
    }

    public class FakePerson
    {
        public string Name { get; set; }
        public string FamilyName { get; set; }
        public string FullName => $"{FamilyName} {Name}";
        public int Age { get; set; }
        public bool IsMale { get; set; }
        public string MailAddress { get; set; }
        public string Password { get; set; }
        public string Address { get; set; }
        public string Tel1 { get; set; }
        public string Tel2 { get; set; }
        public string Tel3 { get; set; }
        public string Tel => $"{Tel1}-{Tel2}-{Tel3}";
    }
}

扱い方

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Test1();
            Test2();
            Console.ReadKey();
        }

        static void Test1()
        {
            for (var i = 0; i < 3; i++)
            {
                Console.WriteLine($"名前     : {FakeData.Person.NextName()}");
                Console.WriteLine($"苗字     : {FakeData.Person.NextFamilyName()}");
                Console.WriteLine($"フルネーム  : {FakeData.Person.NextFullName()}");
                Console.WriteLine($"年齢     : {FakeData.Person.NextAge()}");
                Console.WriteLine($"性別     : {FakeData.Person.NextIsMale()}");
                Console.WriteLine($"メールアドレス: {FakeData.Person.NextMailAddress()}");
                Console.WriteLine($"パスワード  : {FakeData.Person.NextPassword()}");
                Console.WriteLine($"住所     : {FakeData.Person.NextAddress()}");
                Console.WriteLine($"電話番号1  : {FakeData.Person.NextTel1()}");
                Console.WriteLine($"電話番号2  : {FakeData.Person.NextTel2()}");
                Console.WriteLine($"電話番号3  : {FakeData.Person.NextTel3()}");
                Console.WriteLine($"電話番号   : {FakeData.Person.NextTel()}");
                Console.WriteLine("");
            }
        }

        static void Test2()
        {
            var persons = FakeData.Person.Generate(3);
            foreach(var person in persons)
            {
                Console.WriteLine($"名前     : {person.Name}");
                Console.WriteLine($"苗字     : {person.FamilyName}");
                Console.WriteLine($"フルネーム  : {person.FullName}");
                Console.WriteLine($"年齢     : {person.Age}");
                Console.WriteLine($"性別     : {person.IsMale}");
                Console.WriteLine($"メールアドレス: {person.MailAddress}");
                Console.WriteLine($"パスワード  : {person.Password}");
                Console.WriteLine($"住所     : {person.Address}");
                Console.WriteLine($"電話番号1  : {person.Tel1}");
                Console.WriteLine($"電話番号2  : {person.Tel2}");
                Console.WriteLine($"電話番号3  : {person.Tel3}");
                Console.WriteLine($"電話番号   : {person.Tel}");
                Console.WriteLine("");
            }
        }
    }
}

VB.NET のソース

ヘルパークラス

Imports System.Text

Namespace FakeData

    Public Class Person

        Private Shared rnd As Random = New Random

        Public Shared Iterator Function Generate(Optional ByVal count As UInteger = 1) As IEnumerable(Of FakePerson)

            If count <= 0 Then
                Throw New ArgumentException("生成数は 1 以上指定してください。")
            End If

            For i As Integer = 0 To CInt(count - 1)

                Yield New FakePerson With
                {
                    .Name = $"太郎{i + 1}",
                    .FamilyName = NextFamilyName(),
                    .Age = NextAge(),
                    .IsMale = NextIsMale(),
                    .MailAddress = NextMailAddress(),
                    .Password = NextPassword(),
                    .Address = NextAddress(),
                    .Tel1 = NextTel1(),
                    .Tel2 = NextTel2(),
                    .Tel3 = NextTel3()
                }

            Next

        End Function

        Public Shared Function NextName() As String
            Return $"太郎{rnd.Next(1, 100)}"
        End Function

        Public Shared Function NextFamilyName() As String
            Return "サンプル"
        End Function

        Public Shared Function NextFullName() As String
            Return $"{NextFamilyName()} {NextName()}"
        End Function

        Public Shared Function NextAge() As Integer
            Return rnd.Next(20, 81)
        End Function

        Public Shared Function NextIsMale() As Boolean

            If rnd.Next() Mod 2 = 0 Then
                Return True
            Else
                Return False
            End If

        End Function

        Public Shared Function NextMailAddress() As String
            Return $"{RandomMail(8)}@sample.com"
        End Function

        Public Shared Function NextPassword() As String
            Return RandomPassword(12)
        End Function

        Public Shared Function NextAddress() As String
            Return RandomAddress()
        End Function

        Public Shared Function NextTel1() As String

            If rnd.Next() Mod 2 = 0 Then
                Return "080"
            Else
                Return "090"
            End If

        End Function

        Public Shared Function NextTel2() As String
            Return RandomTel(4)
        End Function

        Public Shared Function NextTel3() As String
            Return RandomTel(4)
        End Function

        Public Shared Function NextTel() As String
            Return $"{NextTel1()}-{NextTel2()}-{NextTel3()}"
        End Function

        Private Shared Function RandomMail(ByVal length As Integer) As String

            Dim sb As StringBuilder = New StringBuilder
            Dim pwWords As String = "_-0123456789abcdefghijklmnopqrstuvwxyz"

            ' 最初の 1 文字目は文字列固定
            Dim index As Integer = rnd.Next(12, pwWords.Length)
            sb.Append(pwWords(index))

            For i As Integer = 1 To length - 1

                index = rnd.Next(pwWords.Length)
                sb.Append(pwWords(index))

            Next

            Return sb.ToString()

        End Function

        Private Shared Function RandomPassword(ByVal length As Integer) As String

            Dim sb As StringBuilder = New StringBuilder
            Dim pwWords As String = "_-0123456789abcdefghijklmnopqrstuvwxyz" & "abcdefghijklmnopqrstuvwxyz".ToUpper()

            ' 最初の 1 文字目は文字列固定
            Dim index As Integer = rnd.Next(12, pwWords.Length)
            sb.Append(pwWords(index))

            For i As Integer = 1 To length - 1

                index = rnd.Next(pwWords.Length)
                sb.Append(pwWords(index))

            Next

            Return sb.ToString()

        End Function

        Private Shared Function RandomAddress() As String

            Dim pwWords As List(Of String) = New List(Of String) From {"北海道", "青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県", "茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県", "新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県", "静岡県", "愛知県", "三重県", "滋賀県", "京都府", "大阪府", "兵庫県", "奈良県", "和歌山県", "鳥取県", "島根県", "岡山県", "広島県", "山口県", "徳島県", "香川県", "愛媛県", "高知県", "福岡県", "佐賀県", "長崎県", "熊本県", "大分県", "宮崎県", "鹿児島県", "沖縄県"}
            Return $"{pwWords(rnd.Next(pwWords.Count))}テスト市サンプル123"

        End Function

        Private Shared Function RandomTel(Optional ByVal length As Integer = 4) As String

            Dim sb As StringBuilder = New StringBuilder
            Dim pwWords As String = "0123456789"

            For i As Integer = 1 To length

                Dim Index As Integer = rnd.Next(pwWords.Length)
                sb.Append(pwWords(Index))

            Next

            Return sb.ToString()

        End Function

    End Class

    Public Class FakePerson

        Public Property Name As String
        Public Property FamilyName As String

        Public ReadOnly Property FullName As String
            Get
                Return $"{FamilyName} {Name}"
            End Get
        End Property

        Public Property Age As Integer
        Public Property IsMale As Boolean
        Public Property MailAddress As String
        Public Property Password As String
        Public Property Address As String
        Public Property Tel1 As String
        Public Property Tel2 As String
        Public Property Tel3 As String

        Public ReadOnly Property Tel As String
            Get
                Return $"{Tel1}-{Tel2}-{Tel3}"
            End Get
        End Property

    End Class

End Namespace

扱い方

Module Module1

    Sub Main()

        Test1()
        Test2()
        Console.ReadKey()

    End Sub

    Sub Test1()

        For i As Integer = 0 To 2

            Console.WriteLine($"名前     : {FakeData.Person.NextName()}")
            Console.WriteLine($"苗字     : {FakeData.Person.NextFamilyName()}")
            Console.WriteLine($"フルネーム  : {FakeData.Person.NextFullName()}")
            Console.WriteLine($"年齢     : {FakeData.Person.NextAge()}")
            Console.WriteLine($"性別     : {FakeData.Person.NextIsMale()}")
            Console.WriteLine($"メールアドレス: {FakeData.Person.NextMailAddress()}")
            Console.WriteLine($"パスワード  : {FakeData.Person.NextPassword()}")
            Console.WriteLine($"住所     : {FakeData.Person.NextAddress()}")
            Console.WriteLine($"電話番号1  : {FakeData.Person.NextTel1()}")
            Console.WriteLine($"電話番号2  : {FakeData.Person.NextTel2()}")
            Console.WriteLine($"電話番号3  : {FakeData.Person.NextTel3()}")
            Console.WriteLine($"電話番号   : {FakeData.Person.NextTel()}")
            Console.WriteLine("")

        Next

    End Sub

    Sub Test2()

        Dim persons As IEnumerable(Of FakeData.FakePerson) =
            FakeData.Person.Generate(3)

        For Each person As FakeData.FakePerson In persons

            Console.WriteLine($"名前     : {person.Name}")
            Console.WriteLine($"苗字     : {person.FamilyName}")
            Console.WriteLine($"フルネーム  : {person.FullName}")
            Console.WriteLine($"年齢     : {person.Age}")
            Console.WriteLine($"性別     : {person.IsMale}")
            Console.WriteLine($"メールアドレス: {person.MailAddress}")
            Console.WriteLine($"パスワード  : {person.Password}")
            Console.WriteLine($"住所     : {person.Address}")
            Console.WriteLine($"電話番号1  : {person.Tel1}")
            Console.WriteLine($"電話番号2  : {person.Tel2}")
            Console.WriteLine($"電話番号3  : {person.Tel3}")
            Console.WriteLine($"電話番号   : {person.Tel}")
            Console.WriteLine("")

        Next

    End Sub

End Module