From a9ecbca6522576ca3fe7222628734cacf3112e12 Mon Sep 17 00:00:00 2001 From: hikari Date: Thu, 9 Dec 2021 12:48:16 +0900 Subject: [PATCH 1/2] Match the behavior of SystemRandomSource to System.Random Match the behavior of "SystemRandomSource" to "System.Random" https://github.com/dotnet/runtime/pull/47085 --- src/Numerics/Random/SystemRandomSource.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Numerics/Random/SystemRandomSource.cs b/src/Numerics/Random/SystemRandomSource.cs index 8ecefc43d..72e4d096d 100644 --- a/src/Numerics/Random/SystemRandomSource.cs +++ b/src/Numerics/Random/SystemRandomSource.cs @@ -49,16 +49,18 @@ public class SystemRandomSource : RandomSource /// /// Construct a new random number generator with a random seed. /// - public SystemRandomSource() : this(RandomSeed.Robust()) + public SystemRandomSource() { + _random = new System.Random(); } /// /// Construct a new random number generator with random seed. /// /// if set to true , the class is thread safe. - public SystemRandomSource(bool threadSafe) : this(RandomSeed.Robust(), threadSafe) + public SystemRandomSource(bool threadSafe) : base(threadSafe) { + _random = new System.Random(); } /// @@ -80,7 +82,7 @@ public SystemRandomSource(int seed, bool threadSafe) : base(threadSafe) _random = new System.Random(seed); } - static readonly ThreadLocal DefaultInstance = new ThreadLocal(() => new SystemRandomSource(RandomSeed.Robust(), true)); + static readonly ThreadLocal DefaultInstance = new ThreadLocal(() => new SystemRandomSource(true)); /// /// Default instance, thread-safe. From e293cc3f8edd1fccabeece94e07250cff50c8d22 Mon Sep 17 00:00:00 2001 From: hikari Date: Thu, 9 Dec 2021 19:20:41 +0900 Subject: [PATCH 2/2] Update SystemRandomSource.cs Fixed a seed value issue in the .NET Framework. --- src/Numerics/Random/SystemRandomSource.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Numerics/Random/SystemRandomSource.cs b/src/Numerics/Random/SystemRandomSource.cs index 72e4d096d..a0fd10383 100644 --- a/src/Numerics/Random/SystemRandomSource.cs +++ b/src/Numerics/Random/SystemRandomSource.cs @@ -51,7 +51,11 @@ public class SystemRandomSource : RandomSource /// public SystemRandomSource() { +#if NETCOREAPP _random = new System.Random(); +#else + _random = new System.Random(RandomSeed.Robust()); +#endif } /// @@ -60,7 +64,11 @@ public SystemRandomSource() /// if set to true , the class is thread safe. public SystemRandomSource(bool threadSafe) : base(threadSafe) { +#if NETCOREAPP _random = new System.Random(); +#else + _random = new System.Random(RandomSeed.Robust()); +#endif } ///