Skip to content

Commit

Permalink
Optimize: RandomEx.Create
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnulusGames committed Aug 20, 2024
1 parent d27a5ab commit dd3d111
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 dd3d111

Please sign in to comment.