Files
basic-computer-games/00_Common/dotnet/Games.Common/Randomness/RandomNumberGenerator.cs
2022-03-07 22:03:45 +11:00

23 lines
573 B
C#

using System;
namespace Games.Common.Randomness;
/// <inheritdoc />
public class RandomNumberGenerator : IRandom
{
private Random _random;
private float _previous;
public RandomNumberGenerator()
{
// The BASIC RNG is seeded based on time with a 1 second resolution
_random = new Random((int)(DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond));
}
public float NextFloat() => _previous = (float)_random.NextDouble();
public float PreviousFloat() => _previous;
public void Reseed(int seed) => _random = new Random(seed);
}