Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Online C# Editor for free
- // Write, Edit and Run your C# code using C# Online Compiler
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class HelloWorld
- {
- public static void Main(string[] args)
- {
- var dates = GenerateRandomBirthdates(20, 21, 60);
- foreach(var date in dates)
- {
- var pinfl = FakeGeneratorPinfl(date);
- Console.WriteLine($"BithDate: {date.ToString("yyyy-MM-dd")} - PINFL: {pinfl}");
- }
- }
- public static List<DateTime> GenerateRandomBirthdates(int count, int minAge, int maxAge)
- {
- List<DateTime> birthdates = new List<DateTime>();
- Random random = new Random();
- for (int i = 0; i < count; i++)
- {
- int daysOld = random.Next(minAge * 365, maxAge * 365); // Convert age to days
- birthdates.Add(DateTime.Today.AddDays(-daysOld));
- }
- return birthdates;
- }
- public static string FakeGeneratorPinfl(DateTime birthDate)
- {
- var random = new Random();
- var gender = (Gender)random.Next(0, 2);
- List<int> multipliers = new List<int> { 7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7 };
- int firstDigit;
- if (birthDate.Year >= 1900 && birthDate.Year <= 1999)
- {
- firstDigit = gender == Gender.Male ? 3 : 4;
- }
- else if (birthDate.Year >= 2000 && birthDate.Year <= 2099)
- {
- firstDigit = gender == Gender.Male ? 5 : 6;
- }
- else
- {
- throw new ArgumentOutOfRangeException(nameof(birthDate), "Year must be between 1900 and 2099");
- }
- // Convert date to PINFL part
- var birthDateDigits = birthDate.ToString("ddMMyy").Select(c => c - '0').ToList();
- // Generate 6 random digits
- var randomDigits = new List<int>();
- for (int i = 0; i < 6; i++)
- {
- randomDigits.Add(random.Next(0, 10));
- }
- // Combine all parts
- List<int> pinfl = new List<int> { firstDigit };
- pinfl.AddRange(birthDateDigits);
- pinfl.AddRange(randomDigits);
- // Calculate control digit
- int sum = 0;
- for (int i = 0; i < 13; i++)
- {
- sum += pinfl[i] * multipliers[i];
- }
- int controlDigit = sum % 10;
- // Append control digit
- pinfl.Add(controlDigit);
- return string.Join("", pinfl);
- }
- public enum Gender
- {
- Female =0,
- Male = 1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement