From a989d28e033932020ce308c1074e52d6b7531072 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sat, 12 Oct 2024 21:41:36 -0500 Subject: [PATCH] misc: Convert UIntUtils.CreateRandom into an extension on Random. --- src/Ryujinx.Common/Utilities/UInt128Utils.cs | 18 ++++++++++-------- .../HOS/Services/Mii/UtilityImpl.cs | 2 +- .../Nifm/StaticService/IGeneralService.cs | 2 +- .../HOS/Services/Time/Clock/SteadyClockCore.cs | 2 +- .../Time/Clock/Types/SteadyClockTimePoint.cs | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Common/Utilities/UInt128Utils.cs b/src/Ryujinx.Common/Utilities/UInt128Utils.cs index 113855355..23afaa3a1 100644 --- a/src/Ryujinx.Common/Utilities/UInt128Utils.cs +++ b/src/Ryujinx.Common/Utilities/UInt128Utils.cs @@ -5,14 +5,16 @@ namespace Ryujinx.Common.Utilities { public static class UInt128Utils { - public static UInt128 FromHex(string hex) - { - return new UInt128(ulong.Parse(hex.AsSpan(0, 16), NumberStyles.HexNumber), ulong.Parse(hex.AsSpan(16), NumberStyles.HexNumber)); - } + public static UInt128 FromHex(string hex) => + new( + ulong.Parse(hex.AsSpan(0, 16), NumberStyles.HexNumber), + ulong.Parse(hex.AsSpan(16), NumberStyles.HexNumber) + ); - public static UInt128 CreateRandom() - { - return new UInt128((ulong)Random.Shared.NextInt64(), (ulong)Random.Shared.NextInt64()); - } + public static Int128 NextInt128(this Random rand) => + new((ulong)rand.NextInt64(), (ulong)rand.NextInt64()); + + public static UInt128 NextUInt128(this Random rand) => + new((ulong)rand.NextInt64(), (ulong)rand.NextInt64()); } } diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs b/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs index 32dbb4946..ea54a6ad6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs @@ -63,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii public CreateId MakeCreateId() { - UInt128 value = UInt128Utils.CreateRandom(); + UInt128 value = Random.Shared.NextUInt128(); // Ensure the random ID generated is valid as a create id. value &= ~new UInt128(0xC0, 0); diff --git a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs index 581a2906b..a5a822db3 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs @@ -78,7 +78,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService NetworkProfileData networkProfile = new() { - Uuid = UInt128Utils.CreateRandom(), + Uuid = Random.Shared.NextUInt128(), }; networkProfile.IpSettingData.IpAddressSetting = new IpAddressSetting(interfaceProperties, unicastAddress); diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs index 95cf2a899..98094d35c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock public SteadyClockCore() { - _clockSourceId = UInt128Utils.CreateRandom(); + _clockSourceId = Random.Shared.NextUInt128(); _isRtcResetDetected = false; _isInitialized = false; } diff --git a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs index e4878483d..bce15c672 100644 --- a/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs +++ b/src/Ryujinx.HLE/HOS/Services/Time/Clock/Types/SteadyClockTimePoint.cs @@ -36,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock return new SteadyClockTimePoint { TimePoint = 0, - ClockSourceId = UInt128Utils.CreateRandom(), + ClockSourceId = Random.Shared.NextUInt128(), }; } }