using System;
class Program
{
static void Main()
{
int targetAge = 40;
int minAge = 1;
int maxAge = 100;
int generatedAge = GenerateRandomAge(targetAge, minAge, maxAge);
Console.WriteLine($"Generated Age: {generatedAge}");
}
static int GenerateRandomAge(int targetAge, int minAge, int maxAge)
{
Random random = new Random();
double mean = targetAge; // Mean of the distribution
double standardDeviation = 8; // Standard deviation controls the spread of values
double u1 = 1.0 - random.NextDouble();
double u2 = 1.0 - random.NextDouble();
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2);
double randNormal = mean + standardDeviation * randStdNormal;
int generatedAge = (int)Math.Round(Math.Clamp(randNormal, minAge, maxAge)); // Ensure the generated value is within the specified range
return generatedAge;
}
}