0

How can I retrieve the randomly selected seed value if I write the following?

var randomNumberGenerator = new Random();

I looked at the suggested answers and they do not explain how to get the seed that .Net chose.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
nicomp
  • 4,344
  • 4
  • 27
  • 60
  • AFAIK, by default Random uses time ticks count: https://referencesource.microsoft.com/#mscorlib/system/random.cs – Rafael Oct 06 '22 at 16:05
  • 1
    It is mentioned in the comments of the accepted answer. "The default Random constructor uses Environment.TickCount as the seed". But you want to get this value. Not possible. – Dialecticus Oct 06 '22 at 16:19
  • @Dialecticus Thank you for pointing that out. Intuitively I would assert that the seed must be available somewhere but I accept the verdict of SO on my question. – nicomp Oct 07 '22 at 11:12
  • Source code is the highest authority. You can study the code of `Random` class, given in the link in the first comment here. In the class constructor the seed is broken down into 3 components, `inext`, `inextp`, and `SeedArray`, which are not even accessible from outside. – Dialecticus Oct 07 '22 at 11:22

0 Answers0