Tedd.MoreRandom by Tedd Hansen

<PackageReference Include="Tedd.MoreRandom" Version="1.0.1" />

.NET API 7,168 bytes

 Random

public class Random : IDisposable
using System; using System.Security.Cryptography; namespace Tedd.MoreRandom { public class Random : IDisposable { private readonly RandomNumberGenerator _rng; public Random() { _rng = RandomNumberGenerator.Create(); } public int Next() { return Next(0, 2147483647); } public int Next(int maxValue) { if (maxValue < 0) throw new ArgumentOutOfRangeException("maxValue is less than 0."); return Next(0, maxValue); } public int Next(int minValue, int maxValue) { if (maxValue < minValue) throw new ArgumentOutOfRangeException("minValue is greater than maxValue."); if (maxValue == minValue) return minValue; byte[] array = new byte[4]; int num = maxValue - minValue; int num3; do { _rng.GetBytes(array); double num2 = (double)(uint)((array[0] << 24) | (array[1] << 16) | (array[2] << 8) | array[3]) / 4294967295; num3 = minValue + (int)(num2 * (double)num); } while (num3 >= maxValue); return num3; } public void NextBytes(byte[] buffer) { _rng.GetBytes(buffer); } public byte[] GetByteArray(int size) { byte[] array = new byte[size]; _rng.GetBytes(array); return array; } public double NextDouble() { byte[] array = new byte[8]; double num = 0; do { _rng.GetBytes(array); num = (double)BitConverter.ToUInt64(array, 0) / 1.8446744073709552E+19; } while (!(num < 1)); return num; } private void ReleaseUnmanagedResources() { _rng.Dispose(); } private void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) _rng?.Dispose(); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ~Random() { Dispose(false); } } }