public static Chat GetRandom(DbSet <Profile> profiles) { var rand = new Random(); var nameRand = new RandomNameGeneratorLibrary.PersonNameGenerator(); var memberships = new List <Membership>(); var dd = new Membership(); RandomSeeder.For(20, (_) => { var m = new Membership(); (profiles.ToList().GetRandom() as Profile).Memberships.Add(m); memberships.Add(m); }); var chat = new Chat() { Name = $"Chat{rand.Next() % 100}", CreatedAt = DateTime.Now.ToString(), Memberships = memberships, Messages = Enumerable.Range(0, rand.Next() % 50).Select(i => new Message() { Membership = memberships.GetRandom() as Membership, Text = $"Hey {nameRand.GenerateRandomFirstName()}" }).ToList() }; //memberships.All(el => { el.Chat = chat; return true; }); return(chat); //var memberships = Enumerable.Range(0, rand.Next() % 20).Select(i => new Membership() { Profile = }).ToList(); }
public Tenant(Apartment apartment) { double rageOdds; rageOdds = .1; Trust = 100 - (int)(apartment.AgeInMonths / 2); if (Trust < 50) { Trust = 50; } if (Game1.rand.NextDouble() < rageOdds) { double val = Game1.rand.NextDouble(); if (val < .15) { TemperModifier = 4; RentModifier = 400; } else if (val < .5) { TemperModifier = 3; RentModifier = 200; } else { TemperModifier = 2; RentModifier = 100; } } else { double val = Game1.rand.NextDouble(); if (val < .15) { TemperModifier = .5; } else if (val < .6) { TemperModifier = 1; } else { TemperModifier = 1.5; } RentModifier = 0; } if (nameGenerator == null) { nameGenerator = new RandomNameGeneratorLibrary.PersonNameGenerator(Game1.rand); } Name = nameGenerator.GenerateRandomFirstAndLastName(); }
/// <summary> /// Fills the datacontext with random items /// </summary> /// <param name="sampleDataContext">The datacontext to fill</param> /// <param name="numberOfUsers">The number of random users that the method generates. With this you control the number of rows that the method generates in the users table</param> /// <param name="numberOfComments">the number of random comments that the method generates. With this you control the number of rows that the method generates in the comments table</param> public static void FillDb(SampleDataContext sampleDataContext, int numberOfUsers, int numberOfComments) { RandomNameGeneratorLibrary.PersonNameGenerator personGenerator = new RandomNameGeneratorLibrary.PersonNameGenerator(); RandomNameGeneratorLibrary.PlaceNameGenerator placeGenerator = new RandomNameGeneratorLibrary.PlaceNameGenerator(); Random rnd = new Random(); for (int i = 0; i < numberOfUsers; i++) { var firstName = personGenerator.GenerateRandomFirstName(); var lastLogin = DateTime.Now.AddDays(-rnd.Next(0, 5 * 365)); UserData user = new UserData { Address = "test1234", BirthDate = DateTime.Now.AddYears(-(rnd.Next(17, 90))).AddDays(-(rnd.Next(1, 365))).Date, EmailAddress = firstName + "@testmail.com", UserName = firstName + i, FirstName = firstName, LastName = personGenerator.GenerateRandomLastName(), MidName = rnd.Next(2) == 0 ? String.Empty : personGenerator.GenerateRandomFirstName(), LastLogin = lastLogin, RegistrationDate = lastLogin.AddDays(-(rnd.Next(0, 365))), ZipCode = rnd.Next(0, 10000) }; sampleDataContext.Users.Add(user); } sampleDataContext.SaveChanges(); var authors = sampleDataContext.Users.ToList(); //need ToList, since ElementAt is currently not supported Comment comment = new Comment(); for (int i = 0; i < numberOfComments; i++) { var author = authors.ElementAt(rnd.Next(0, authors.Count())); comment = new Comment() { Author = author, Created = author.LastLogin.AddDays(-rnd.Next(0, 150)), Text = "comment text " + i }; sampleDataContext.Comments.Add(comment); if (i % 100_000 == 0) { sampleDataContext.SaveChanges(); } } sampleDataContext.SaveChanges(); }
public static Message GetRandom(DbSet <Membership> memberships) { var nameRand = new RandomNameGeneratorLibrary.PersonNameGenerator(); var placeRand = new RandomNameGeneratorLibrary.PlaceNameGenerator(); return(new Message() { CreatedAt = DateTime.Now.ToString(), Text = $"{nameRand.GenerateRandomFirstName()} {nameRand.GenerateRandomLastName()} at {placeRand.GenerateRandomPlaceName()}", Membership = memberships.ToList().GetRandom() as Membership }); }
public static User GetRandom() { var rand = new Random(); var nameRand = new RandomNameGeneratorLibrary.PersonNameGenerator(); return(new User() { Name = $"User{rand.Next() % 100}", PasswordHash = $"1234", PasswordSalt = $"", CreatedAt = DateTime.Now.ToString(), Profile = Profile.GetRandom() }); }
public static Profile GetRandom() { var rand = new Random(); var nameRand = new RandomNameGeneratorLibrary.PersonNameGenerator(); return(new Profile() { FirstName = nameRand.GenerateRandomFirstName(), LastName = nameRand.GenerateRandomLastName(), Gender = 2, Role = new Role() { Name = $"Role" } }); }
public void TestAdd() { Repository.Teacher repo = new Repository.Teacher(); RandomNameGeneratorLibrary.PersonNameGenerator personNameGenerator = new RandomNameGeneratorLibrary.PersonNameGenerator(); for (int i = 0; i < 100; i++) { Repository.Model.Teacher t = new Repository.Model.Teacher(); Random r = new Random(); int a = r.Next(0, 2); if (a == 0) { t.TeacherName = personNameGenerator.GenerateRandomFemaleFirstAndLastName(); t.Gender = "女"; } else { t.TeacherName = personNameGenerator.GenerateRandomMaleFirstAndLastName(); t.Gender = "男"; } repo.Add(t); } List <Repository.Model.Teacher> teachers = repo.GetList(); foreach (Repository.Model.Teacher t in teachers) { Console.WriteLine(t.TeacherName); } }