From 11aae9cfbc07d337c8b222e15f5d8e676f3bf46f Mon Sep 17 00:00:00 2001 From: Berkan Diler Date: Wed, 16 Nov 2022 19:34:18 +0100 Subject: [PATCH] Make use of Random.Shared (#3852) --- .../HOS/Services/Friend/ServiceCreator/IFriendService.cs | 3 +-- Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs | 2 +- Ryujinx.HLE/HOS/Services/Prepo/IPrepoService.cs | 2 +- Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs | 4 +--- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs b/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs index 1cf03f5bc..77499fa53 100644 --- a/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs +++ b/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs @@ -266,9 +266,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator // NOTE: Calls nn::friends::detail::service::core::PlayHistoryManager::GetInstance and stores the instance. byte[] randomBytes = new byte[8]; - Random random = new Random(); - random.NextBytes(randomBytes); + Random.Shared.NextBytes(randomBytes); // NOTE: Calls nn::friends::detail::service::core::UuidManager::GetInstance and stores the instance. // Then call nn::friends::detail::service::core::AccountStorageManager::GetInstance and store the instance. diff --git a/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs b/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs index 851b67a5b..4e445c4fc 100644 --- a/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs +++ b/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs @@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp { byte[] uuid = new byte[9]; - new Random().NextBytes(uuid); + Random.Shared.NextBytes(uuid); uuid[3] = (byte)(0x88 ^ uuid[0] ^ uuid[1] ^ uuid[2]); uuid[8] = (byte)(uuid[3] ^ uuid[4] ^ uuid[5] ^ uuid[6]); diff --git a/Ryujinx.HLE/HOS/Services/Prepo/IPrepoService.cs b/Ryujinx.HLE/HOS/Services/Prepo/IPrepoService.cs index 3fa1182db..019626f1b 100644 --- a/Ryujinx.HLE/HOS/Services/Prepo/IPrepoService.cs +++ b/Ryujinx.HLE/HOS/Services/Prepo/IPrepoService.cs @@ -89,7 +89,7 @@ namespace Ryujinx.HLE.HOS.Services.Prepo { byte[] randomBuffer = new byte[8]; - new Random().NextBytes(randomBuffer); + Random.Shared.NextBytes(randomBuffer); _systemSessionId = BitConverter.ToUInt64(randomBuffer, 0); } diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs index 5590bfddf..0d1ae27f2 100644 --- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs @@ -32,8 +32,6 @@ namespace Ryujinx.HLE.HOS.Services.Ro private KProcess _owner; private IVirtualMemoryManager _ownerMm; - private static Random _random = new Random(); - public IRoInterface(ServiceCtx context) { _nrrInfos = new List(MaxNrr); @@ -283,7 +281,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro { while (true) { - ulong randomOffset = (ulong)(uint)_random.Next(0, (int)addressSpacePageLimit) << 12; + ulong randomOffset = (ulong)(uint)Random.Shared.Next(0, (int)addressSpacePageLimit) << 12; targetAddress = memMgr.GetAddrSpaceBaseAddr() + randomOffset;