Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match the behavior of SystemRandomSource to System.Random #886

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Numerics/Random/SystemRandomSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,26 @@ public class SystemRandomSource : RandomSource
/// <summary>
/// Construct a new random number generator with a random seed.
/// </summary>
public SystemRandomSource() : this(RandomSeed.Robust())
public SystemRandomSource()
{
#if NETCOREAPP
_random = new System.Random();
#else
_random = new System.Random(RandomSeed.Robust());
#endif
}

/// <summary>
/// Construct a new random number generator with random seed.
/// </summary>
/// <param name="threadSafe">if set to <c>true</c> , the class is thread safe.</param>
public SystemRandomSource(bool threadSafe) : this(RandomSeed.Robust(), threadSafe)
public SystemRandomSource(bool threadSafe) : base(threadSafe)
{
#if NETCOREAPP
_random = new System.Random();
#else
_random = new System.Random(RandomSeed.Robust());
#endif
}

/// <summary>
Expand All @@ -80,7 +90,7 @@ public SystemRandomSource(int seed, bool threadSafe) : base(threadSafe)
_random = new System.Random(seed);
}

static readonly ThreadLocal<SystemRandomSource> DefaultInstance = new ThreadLocal<SystemRandomSource>(() => new SystemRandomSource(RandomSeed.Robust(), true));
static readonly ThreadLocal<SystemRandomSource> DefaultInstance = new ThreadLocal<SystemRandomSource>(() => new SystemRandomSource(true));

/// <summary>
/// Default instance, thread-safe.
Expand Down