Skip to content

Commit

Permalink
Merge pull request #6 from AnnulusGames/optimize-randomex-create
Browse files Browse the repository at this point in the history
Optimize: RandomEx.Create
  • Loading branch information
AnnulusGames committed Aug 20, 2024
2 parents d27a5ab + dd3d111 commit 19f0ef4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/RandomExtensions/RandomEx.Shared.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace RandomExtensions;
namespace RandomExtensions;

public static partial class RandomEx
{
[ThreadStatic] static Random? seedGenerator;
static Random SeedGenerator => seedGenerator ??= new();

/// <summary>
/// Provides a thread-safe IRandom instance that may be used concurrently from any thread.
/// </summary>
Expand All @@ -12,7 +15,7 @@ public static partial class RandomEx
/// </summary>
public static IRandom Create()
{
return new Xoshiro256StarStarRandom((uint)new Random().Next());
return new Xoshiro256StarStarRandom((uint)SeedGenerator.Next());
}
}

Expand Down

0 comments on commit 19f0ef4

Please sign in to comment.