private DateTime RandomDate(DateTime startDate, TriangularDistribution triangularDistribution) { TimeSpan newSpan = new TimeSpan(0, (int)triangularDistribution.GetNext(), 0); DateTime newDate = startDate + newSpan; return(newDate.Date); }
public Pacients CreatePacients(int count) { Pacients pacients = new Pacients(); var startDate = new DateTime(1950, 1, 1); var endDate = new DateTime(2019, 12, 31); TriangularDistribution triangularDistribution = new TriangularDistribution(_random.Next(), 0, (int)(endDate - startDate).TotalMinutes, (int)(endDate - startDate).TotalMinutes / 2); for (int i = 0; i < count; i++) { DateTime dateTime = RandomDate(startDate, triangularDistribution); string date = ""; if (_random.Next(0, 100) < 50) { date = dateTime.ToString("yy") + (dateTime.Month + 50) + dateTime.ToString("dd") + "0000"; } else { date = dateTime.ToString("yyMMdd") + "0000"; } long pid = Convert.ToInt64(date) + i; long b = pid % 11; pid += 11 - b; Pacient pacient = new Pacient() { PID = pid.ToString("######/####"), FirstName = GetRandomName(), LastName = GetRandomName(), BirthDate = dateTime, Height = _heightDistribution.GetNext(), Weight = _weightDistribution.GetNext(), }; pacients.Add(pacient); } return(pacients); }