57 lines
1.2 KiB
C#
57 lines
1.2 KiB
C#
public class TrackedRng
|
|
{
|
|
private readonly System.Random _rng;
|
|
private readonly int _seed;
|
|
private int _stepCount;
|
|
public int Seed => _seed;
|
|
public int StepCount => _stepCount;
|
|
public TrackedRngState State => new TrackedRngState() { Seed = _seed, StepCount = _stepCount };
|
|
|
|
public TrackedRng(int seed, int stepCount = 0)
|
|
{
|
|
_rng = new System.Random(seed);
|
|
_seed = seed;
|
|
_stepCount = stepCount;
|
|
while (stepCount-- > 0)
|
|
_rng.Next();
|
|
}
|
|
|
|
public TrackedRng(TrackedRngState state)
|
|
{
|
|
_rng = new System.Random(state.Seed);
|
|
_seed = state.Seed;
|
|
_stepCount = state.StepCount;
|
|
while (state.StepCount-- > 0)
|
|
_rng.Next();
|
|
}
|
|
|
|
public int Next()
|
|
{
|
|
_stepCount++;
|
|
return _rng.Next();
|
|
}
|
|
|
|
public int Next(int maxValue)
|
|
{
|
|
_stepCount++;
|
|
return _rng.Next(maxValue);
|
|
}
|
|
|
|
public int Next(int minValue, int maxValue)
|
|
{
|
|
_stepCount++;
|
|
return _rng.Next(minValue, maxValue);
|
|
}
|
|
|
|
/* private void AdvanceBySteps(int stepCount)
|
|
{
|
|
while (stepCount-- > 0)
|
|
_rng.Next();
|
|
} */
|
|
}
|
|
|
|
public class TrackedRngState
|
|
{
|
|
public int StepCount = 0;
|
|
public int Seed;
|
|
} |