feat(rng-seam): SeededRandomSource mirrors the engine's two System.Random streams
This commit is contained in:
22
SVSim.BattleEngine/Rng/SeededRandomSource.cs
Normal file
22
SVSim.BattleEngine/Rng/SeededRandomSource.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace SVSim.BattleEngine.Rng
|
||||
{
|
||||
// Default source. Faithfully reproduces the engine's own RNG: BattleManagerBase seeds two separate
|
||||
// System.Random(RandomSeed) instances (_stableRandom synced, _stableRandomOnlySelf self-only) at
|
||||
// BattleManagerBase.cs:721-722. The authoritative server uses this; tests use ScriptedRandomSource.
|
||||
public sealed class SeededRandomSource : IRandomSource
|
||||
{
|
||||
private readonly Random _synced;
|
||||
private readonly Random _self;
|
||||
|
||||
public SeededRandomSource(int seed)
|
||||
{
|
||||
_synced = new Random(seed);
|
||||
_self = new Random(seed);
|
||||
}
|
||||
|
||||
public double NextUnit() => _synced.NextDouble();
|
||||
public int NextSelf(int max) => _self.Next(max);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user