sharp-chat/SharpChat/RNG.cs
2023-02-07 16:01:56 +01:00

30 lines
837 B
C#

using System;
using System.Security.Cryptography;
namespace SharpChat {
public static class RNG {
private static object Lock { get; } = new();
private static Random NormalRandom { get; } = new();
private static RandomNumberGenerator SecureRandom { get; } = RandomNumberGenerator.Create();
public static int Next() {
lock(Lock)
return NormalRandom.Next();
}
public static int Next(int max) {
lock(Lock)
return NormalRandom.Next(max);
}
public static int Next(int min, int max) {
lock(Lock)
return NormalRandom.Next(min, max);
}
public static void NextBytes(byte[] buffer) {
lock(Lock)
SecureRandom.GetBytes(buffer);
}
}
}