-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomEntityGenerator.cs
More file actions
81 lines (67 loc) · 2.37 KB
/
RandomEntityGenerator.cs
File metadata and controls
81 lines (67 loc) · 2.37 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Client.Library;
public class RandomEntityGenerator
{
private static readonly string[] FirstNames =
{
"Alice","Bob","Carol","David","Eva","Frank","Grace","Henry","Ivy","Jack",
"Kara","Liam","Mona","Nate","Olive","Paul","Quinn","Rita","Sam","Tara",
"Uma","Vince","Wade","Xena","Yuri","Zane"
};
private static readonly string[] LastNames =
{
"Anderson","Baker","Carter","Dixon","Edwards","Foster","Garcia","Harris",
"Irwin","Johnson","King","Lopez","Miller","Nelson","Owens","Parker",
"Quinn","Roberts","Stevens","Turner","Ulrich","Vasquez","White","Xu",
"Young","Zimmerman"
};
private static readonly string[] DogNames =
{
"Buddy","Bella","Max","Luna","Rocky","Lucy","Charlie","Daisy","Milo","Sadie"
};
private static readonly string[] DogBreeds =
{
"Labrador","Beagle","Bulldog","Poodle","Golden Retriever","Boxer","Dachshund","Spaniel"
};
private readonly Random _rng;
public RandomEntityGenerator(int? seed = null)
{
_rng = seed.HasValue ? new Random(seed.Value) : new Random();
}
public List<Person> GeneratePersons(int count)
{
var persons = new List<Person>(count);
for (int i = 0; i < count; i++)
{
var first = FirstNames[_rng.Next(FirstNames.Length)];
var last = LastNames[_rng.Next(LastNames.Length)];
// Make names more likely unique by appending index or random number
string fullName = $"{first} {last}{(_rng.Next(0, 3) == 0 ? $" #{i + 1}" : "")}";
int age = _rng.Next(12, 121); // 12–120 inclusive
Dog? pet = null;
if (_rng.NextDouble() < 0.75) // 75% chance to have a pet because pets are cool
{
pet = GenerateDog();
}
persons.Add(new Person()
{
Id = i,
Name = fullName,
Age = age,
Pets = pet == null ? [] : [ pet ]
});
}
return persons;
}
public Dog GenerateDog()
{
return new()
{
Name = DogNames[_rng.Next(DogNames.Length)],
Breed = DogBreeds[_rng.Next(DogBreeds.Length)],
Age = _rng.Next(1, 21) // Pet age 1 to 20
};
}
}