mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Random timespan support (#3458)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
@@ -11,6 +12,8 @@ namespace Robust.Shared.Random
|
||||
public float NextFloat(float maxValue) => NextFloat() * maxValue;
|
||||
int Next();
|
||||
int Next(int minValue, int maxValue);
|
||||
TimeSpan Next(TimeSpan minTime, TimeSpan maxTime);
|
||||
TimeSpan Next(TimeSpan maxTime);
|
||||
int Next(int maxValue);
|
||||
double NextDouble();
|
||||
double NextDouble(double minValue, double maxValue) => NextDouble() * (maxValue - minValue) + minValue;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using System;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.Random
|
||||
{
|
||||
public sealed class RobustRandom : IRobustRandom
|
||||
@@ -19,6 +22,17 @@ namespace Robust.Shared.Random
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user