Skip to content

Instantly share code, notes, and snippets.

@gpc91
Created November 30, 2022 15:49
Show Gist options
  • Save gpc91/bd63aa17a86b02121f4bb7ec3294d302 to your computer and use it in GitHub Desktop.
Save gpc91/bd63aa17a86b02121f4bb7ec3294d302 to your computer and use it in GitHub Desktop.
System.Random Next ulong (UInt64) extension
/// <summary>
/// Extension methods for the <see cref="System.Random"/> class.
/// </summary>
public static class RandomExtensions
{
/// <summary>
/// Returns a random unsigned ulong
/// </summary>
public static UInt64 NextUInt64(this Random random)
{
byte[] buffer = new byte[System.Runtime.InteropServices.Marshal.SizeOf(typeof(UInt64))];
random.NextBytes(buffer);
return BitConverter.ToUInt64(buffer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment