first commit
This commit is contained in:
37
NitroxServer/Helper/DeterministicGenerator.cs
Normal file
37
NitroxServer/Helper/DeterministicGenerator.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
|
||||
namespace NitroxServer.Helper
|
||||
{
|
||||
public class DeterministicGenerator
|
||||
{
|
||||
private readonly Random random;
|
||||
|
||||
public DeterministicGenerator(string worldSeed, object reference)
|
||||
{
|
||||
random = new Random(worldSeed.GetHashCode() + reference.GetHashCode());
|
||||
}
|
||||
|
||||
public double NextDouble()
|
||||
{
|
||||
return random.NextDouble();
|
||||
}
|
||||
|
||||
public double NextDouble(double min, double max)
|
||||
{
|
||||
return random.NextDouble() * (max - min) + min;
|
||||
}
|
||||
|
||||
public int NextInt(int min, int max)
|
||||
{
|
||||
return random.Next(min, max);
|
||||
}
|
||||
|
||||
public NitroxId NextId()
|
||||
{
|
||||
byte[] bytes = new byte[16];
|
||||
random.NextBytes(bytes);
|
||||
return new NitroxId(bytes);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user