Initial commit
This commit is contained in:
43
PkmnLib.Static/Utils/Random.cs
Normal file
43
PkmnLib.Static/Utils/Random.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace PkmnLib.Static.Utils;
|
||||
|
||||
public interface IRandom
|
||||
{
|
||||
public int GetInt(int min, int max);
|
||||
public int GetInt(int max);
|
||||
public int GetInt();
|
||||
public float GetFloat();
|
||||
public float GetFloat(float min, float max);
|
||||
public bool GetBool();
|
||||
}
|
||||
|
||||
public class RandomImpl : IRandom
|
||||
{
|
||||
private Random _random;
|
||||
|
||||
public RandomImpl(Random random)
|
||||
{
|
||||
_random = random;
|
||||
}
|
||||
|
||||
public RandomImpl(int seed)
|
||||
{
|
||||
_random = new Random(seed);
|
||||
}
|
||||
|
||||
public RandomImpl()
|
||||
{
|
||||
_random = new Random();
|
||||
}
|
||||
|
||||
public int GetInt(int min, int max) => _random.Next(min, max);
|
||||
|
||||
public int GetInt(int max) => _random.Next(max);
|
||||
|
||||
public int GetInt() => _random.Next();
|
||||
|
||||
public float GetFloat() => (float)_random.NextDouble();
|
||||
|
||||
public float GetFloat(float min, float max) => (float)(_random.NextDouble() * (max - min) + min);
|
||||
|
||||
public bool GetBool() => _random.Next(2) == 1;
|
||||
}
|
||||
Reference in New Issue
Block a user