using System; namespace AlicizaX { /// /// 随机数帮助类 /// public static class RandomHelper { private static Random _random = new Random((int) DateTime.UtcNow.Ticks); /// /// 设置随机种子 /// /// public static void SetSeed(int seed) { _random = new Random(seed); } /// /// 获取UInt64范围内的随机数 /// /// public static ulong NextUInt64() { var bytes = new byte[8]; _random.NextBytes(bytes); return BitConverter.ToUInt64(bytes, 0); } /// /// 获取Int64范围内的随机数 /// /// public static long NextInt64() { var bytes = new byte[8]; _random.NextBytes(bytes); return BitConverter.ToInt64(bytes, 0); } /// /// 获取lower与Upper之间的随机数 /// /// /// /// public static int Next(int lower, int upper) { return _random.Next(lower, upper); } /// /// 获取0与1之间的随机数 /// /// public static float Next() { return _random.Next(0, 100_000) / 100_000f; } } }