fix: Use built-in RNG (#1599)

### Summary

.NET 8 supports Xoroshiro 256** off the shelf and added Shuffle. Switching to that implementation.

### Developer Notes

* Removed many convenience methods that weren't used.
This commit is contained in:
Kamron Batman 2023-11-17 17:45:18 -08:00 • committed by GitHub
parent 1769d47ba5
commit dba3ec2db5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 159 additions and 699 deletions

View file

@ -22,9 +22,7 @@ namespace Server.Accounting.Security
{
public static IPasswordProtection Instance = new Argon2PasswordProtection();
private readonly Argon2PasswordHasher m_PasswordHasher = new(
rng: (RandomSources.SecureSource as SecureRandom)?.Generator
);
private readonly Argon2PasswordHasher m_PasswordHasher = new(rng: BuiltInSecureRng.Generator);
public string EncryptPassword(string plainPassword) =>
m_PasswordHasher.Hash(plainPassword);

View file

@ -15,6 +15,6 @@ public class ResetRng
)]
private static void ResetRng_OnCommand(CommandEventArgs e)
{
RandomSources.SetRng(new Xoshiro256PlusPlus());
BuiltInRng.Reset();
}
}

View file

@ -60,7 +60,7 @@ namespace Server.Engines.Harvest
if (Definition.RandomizeVeins)
{
m_DefaultVein = Definition.GetVeinFrom(Utility.Random(Definition.VeinWeights));
m_DefaultVein = Definition.GetVeinFrom((uint)Utility.Random(Definition.VeinWeights));
}
m_Vein = m_DefaultVein;

View file

@ -135,12 +135,12 @@ namespace Server.Engines.Harvest
if (RandomizeVeins)
{
return GetVeinFrom(Utility.Random(1000u));
return GetVeinFrom((uint)Utility.Random(1000));
}
// TODO: Introduce pulling primes from a config and writing them if they don't exist to the config
var random = new Xoshiro256PlusPlus((ulong)(x * 17 + y * 11 + map.MapID * 3));
return GetVeinFrom(random.Next(VeinWeights));
var seed = (ulong)(x * 17 + y * 11 + map.MapID * 3);
return GetVeinFrom((uint)StableRandom.First(seed, VeinWeights));
}
public HarvestVein GetVeinFrom(uint randomValue)