Best way to seed Random() in singleton
.net, c#
Solution
Instead of trying to come up with a better seed yourself, use System.Security.Cryptography.RandomNumberGenerator.
It uses a seed based on a complex algorithm that involves a lot of different environment variables. System time is one of those, as is IIRC the MAC address of your NIC, etc.
It is also considered a 'more random' algorithm than the one implemented by the Random class.
Problem
I have a method in a singleton class that need to use the .NET System. `Random()`, since the method is called in a multi-threaded environment I can't create it only once and declare it statically, but I have to create a `Random()` object each time the method is called. Since `Random()` default seed is based on the clock ticks it is not random enough in my senario. To create a better seed I have looked into several methods and have figured the following one is the best, but there may be other (faster/better) ways of doing this that I would like to know about. ``` Random rnd = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0)); ```