-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feature: turn GetFirstEnabledActions into GetAction * Feature: add params to constructors * Fix: move ThreadSafeRandom into namespace * Fix: swap parameters in test * Fix: apply suggestions from code review Co-authored-by: Jens Steenmetz <35835627+JensSteenmetz@users.noreply.github.com> * Fix: prevent index out of range exception * Feature: add test * Fix: scope of variable --------- Co-authored-by: Jens Steenmetz <35835627+JensSteenmetz@users.noreply.github.com>
- Loading branch information
1 parent
368b141
commit 826ae60
Showing
6 changed files
with
100 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
|
||
namespace Aplib.Core | ||
{ | ||
internal static class ThreadSafeRandom | ||
{ | ||
[ThreadStatic] | ||
private static Random? _local; | ||
private static readonly Random _global = new(); | ||
|
||
private static Random _instance | ||
{ | ||
get | ||
{ | ||
if (_local is null) | ||
{ | ||
int seed; | ||
lock (_global) | ||
{ | ||
seed = _global.Next(); | ||
} | ||
|
||
_local = new Random(seed); | ||
} | ||
|
||
return _local; | ||
} | ||
} | ||
|
||
public static int Next() => _instance.Next(); | ||
|
||
public static int Next(int maxValue) => _instance.Next(maxValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters