Random number generators depend on a good seed in order to provide real random numbers. On source for good seed is to take the input of the user, since human behaviours is not deterministic.
One way to do that is to let user's enter some characters and measure the time between the keystrokes. Here some code to illustrate this:
Console.WriteLine("please enter some text (at least 10 characters)");
DateTime startDateTime = DateTime.Now;
List<double> timeStamps = new List<double>();
ConsoleKeyInfo cki;
int cnt = 0;
do
{
cki = Console.ReadKey();
double timeStamp = DateTime.Now.Subtract(startDateTime).TotalMilliseconds;
timeStamps.Add(timeStamp);
cnt++;
}
while ( (cki.Key != ConsoleKey.Enter) || (cnt<3) );
Console.WriteLine();
The code above measures the time bertween the keystores, which are saved in array timeStamps.
Using this human data, which calculate a seed like this:
double sum = timeStamps.Sum(v => v * 20);
int seed = Convert.ToInt32(sum);
Console.WriteLine($"seed: {seed}");
And then we can calculate real random numbers:
Console.WriteLine("5 random values:");
Random rnd = new Random(seed);
for(int i=0;i<5;i++)
{
int n = rnd.Next(100, 200);
Console.WriteLine(n);
}
I'm interested in you opinion and your thoughts about my approach. Interesting enough I have never seen a solution like this on the internet.