Do multiple instances of System.Random still use the same seed in .Net Core?

Mar*_*ato 8 c# .net-core

I've seen several articles talking about not generating too many System.Random instances too closely together because they'll be seeded with the same value from the system clock and thus return the same set of numbers:

  1. /sf/answers/189457621/
  2. https://codeblog.jonskeet.uk/2009/11/04/revisiting-randomness/
  3. https://docs.microsoft.com/en-us/dotnet/api/system.random?view=netframework-4.8#instantiating-the-random-number-generator

That appears to be true for .net framework 4.8. Looking at the source code for .net core, however, it looks like instances of System.Random generated on the same thread are seeded from a [ThreadStatic] generator. So it would seem to me that, in .net core, you are now safe to do something like:

Random[] randoms = new Random[1000];
for (int i = 0; i < randoms.Length; i++)
{
  randoms[i] = new Random();
}
// use Random instances and they'll all have distinct generated patterns
Run Code Online (Sandbox Code Playgroud)

Is this true? Am I missing something?

Note: Assume we're talking about a single thread here (although I'm not sure it matters because it looks like .net core uses bcrypt or something to seed the global generator per-thread?).

EDIT: This is now tracked in this ticket.

Dav*_*oft 5

Is this true? Am I missing something?

我相信您对源代码的阅读是正确的。但是除非记录下来,否则您不应该依赖此行为。我的猜测是文档只是跟不上实现,但是您可以在此处打开一个问题来更新文档。

.NET Core具有许多类似的小改进,出于向后兼容的原因,您可能会犹豫对.NET Framework进行一些改进。