Files
RobustToolbox/Robust.Shared/Random/RobustRandom.cs
T
metalgearslothandGitHub 2f7a652e22 Add helper methods for System.Random (#3832)
This might be a maint thing but look, I just want seeded RNG and IRobustRandom doesn't have it so not sure what is easier considering IRobustRandom is also registered as a depdency but constructing it manually is weird aaaa
2023-03-09 16:04:23 -06:00

54 lines
1.2 KiB
C#

using System;
using Robust.Shared.Utility;
namespace Robust.Shared.Random
{
public sealed class RobustRandom : IRobustRandom
{
private readonly System.Random _random = new();
public System.Random GetRandom() => _random;
public float NextFloat()
{
return _random.NextFloat();
}
public int Next()
{
return _random.Next();
}
public int Next(int minValue, int maxValue)
{
return _random.Next(minValue, maxValue);
}
public TimeSpan Next(TimeSpan minTime, TimeSpan maxTime)
{
DebugTools.Assert(minTime < maxTime);
return minTime + (maxTime - minTime) * _random.NextDouble();
}
public TimeSpan Next(TimeSpan maxTime)
{
return Next(TimeSpan.Zero, maxTime);
}
public int Next(int maxValue)
{
return _random.Next(maxValue);
}
public double NextDouble()
{
return _random.NextDouble();
}
public void NextBytes(byte[] buffer)
{
_random.NextBytes(buffer);
}
}
}