private static unsafe ulong GenerateSeed() { ulong seed; Interop.GetRandomBytes((byte *)&seed, sizeof(ulong)); return(seed); }
private static unsafe uint GenerateGlobalSeed() { uint result; Interop.GetRandomBytes((byte *)&result, sizeof(uint)); return(result); }
private static unsafe ulong GenerateSeed() { ulong result; Interop.GetRandomBytes((byte *)&result, sizeof(ulong)); return(result); }
public unsafe XoshiroImpl() { #if WINDOWS ulong *ptr = stackalloc ulong[4]; #elif EFI EfiImpl byteGen = new(); //TODO Use stackalloc? byte[] bPtr = new byte[4 * sizeof(ulong)]; #endif do { //TODO Add this function as soon as having reference type static fields is possible, this would avoid reinitialising EfiImpl or //at least not using LocateHandle/OpenProtocol every time in order to access EFI_RNG_PROTOCOL.GetBytes #if WINDOWS Interop.GetRandomBytes((byte *)ptr, 4 * sizeof(ulong)); #elif EFI byteGen.NextBytes(bPtr); ulong[] ptr = Unsafe.As <ulong[]>(bPtr); #endif _s0 = ptr[0]; _s1 = ptr[1]; _s2 = ptr[2]; _s3 = ptr[3]; #if EFI ptr.Free(); #endif }while ((_s0 | _s1 | _s2 | _s3) == 0); // at least one value must be non-zero #if EFI bPtr.Free(); byteGen.Free(); #endif }
private static unsafe ulong GenerateSeed() { #if MONO return(12874512); #else ulong seed; Interop.GetRandomBytes((byte *)&seed, sizeof(ulong)); return(seed); #endif }
public unsafe XoshiroImpl() { ulong *ptr = stackalloc ulong[4]; do { Interop.GetRandomBytes((byte *)ptr, 4 * sizeof(ulong)); _s0 = ptr[0]; _s1 = ptr[1]; _s2 = ptr[2]; _s3 = ptr[3]; }while ((_s0 | _s1 | _s2 | _s3) == 0); // at least one value must be non-zero }
private static ulong GenerateSeed() { #if MONO return(839433921); #else ulong seed; unsafe { Interop.GetRandomBytes((byte *)&seed, sizeof(ulong)); } return(seed); #endif }
// used in ModuleBuilder so mcs doesn't need to invoke // CryptoConfig for simple assemblies. internal static unsafe byte[] FastNewGuidArray() { byte[] guid = new byte [16]; fixed(byte *ptr = guid) { Interop.GetRandomBytes(ptr, 16); } // Mask in Variant 1-0 in Bit[7..6] guid [8] = (byte)((guid [8] & 0x3f) | 0x80); // Mask in Version 4 (random based Guid) in Bits[15..13] guid [7] = (byte)((guid [7] & 0x0f) | 0x40); return(guid); }
// This will create a new random guid based on the https://www.ietf.org/rfc/rfc4122.txt public static unsafe Guid NewGuid() { Guid g; Interop.GetRandomBytes((byte *)&g, sizeof(Guid)); const ushort VersionMask = 0xF000; const ushort RandomGuidVersion = 0x4000; const byte ClockSeqHiAndReservedMask = 0xC0; const byte ClockSeqHiAndReservedValue = 0x80; // Modify bits indicating the type of the GUID unchecked { // time_hi_and_version g._c = (short)((g._c & ~VersionMask) | RandomGuidVersion); // clock_seq_hi_and_reserved g._d = (byte)((g._d & ~ClockSeqHiAndReservedMask) | ClockSeqHiAndReservedValue); } return(g); }