mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-07 02:08:17 +02:00
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
54 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|