feat(rng-seam): SeededRandomSource mirrors the engine's two System.Random streams

This commit is contained in:
gamer147
2026-06-06 10:18:19 -04:00
parent c77d789558
commit 2fd42c10cf
2 changed files with 40 additions and 0 deletions

View File

@@ -17,5 +17,23 @@ namespace SVSim.BattleEngine.Tests
Assert.That(RandomSourceBridge.Range(3, 0.5), Is.EqualTo(1)); // floor(1.5) = 1 (middle of 3)
Assert.That(RandomSourceBridge.Range(1, 0.5), Is.EqualTo(0)); // floor(0.5) = 0
}
// SeededRandomSource(seed) must reproduce the engine's own generators EXACTLY: BattleManagerBase
// seeds both _stableRandom and _stableRandomOnlySelf as `new System.Random(RandomSeed)`
// (BattleManagerBase.cs:721-722). NextUnit() == synced.NextDouble(); NextSelf(max) == self.Next(max).
[Test]
public void SeededSource_reproduces_two_System_Random_streams()
{
const int seed = 12345;
var src = new SeededRandomSource(seed);
var refSynced = new System.Random(seed); // mirrors _stableRandom
var refSelf = new System.Random(seed); // mirrors _stableRandomOnlySelf (separate stream)
for (int i = 0; i < 8; i++)
Assert.That(src.NextUnit(), Is.EqualTo(refSynced.NextDouble()), $"NextUnit drift at {i}");
for (int i = 0; i < 8; i++)
Assert.That(src.NextSelf(100), Is.EqualTo(refSelf.Next(100)), $"NextSelf drift at {i}");
}
}
}