Created
November 30, 2022 15:49
-
-
Save gpc91/bd63aa17a86b02121f4bb7ec3294d302 to your computer and use it in GitHub Desktop.
System.Random Next ulong (UInt64) extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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