diff --git a/PKHeX.Core/Editing/WurmpleUtil.cs b/PKHeX.Core/Editing/WurmpleUtil.cs index 947123380..34951f119 100644 --- a/PKHeX.Core/Editing/WurmpleUtil.cs +++ b/PKHeX.Core/Editing/WurmpleUtil.cs @@ -38,7 +38,8 @@ public static int GetWurmpleEvoGroup(int species) public static uint GetWurmpleEncryptionConstant(int evoVal) { uint result; - do result = Util.Rand32(); + var rnd = Util.Rand; + do result = rnd.Rand32(); while (evoVal != GetWurmpleEvoVal(result)); return result; } diff --git a/PKHeX.Core/Legality/RNG/Overworld8RNG.cs b/PKHeX.Core/Legality/RNG/Overworld8RNG.cs index 29aa9e998..b3145a2b7 100644 --- a/PKHeX.Core/Legality/RNG/Overworld8RNG.cs +++ b/PKHeX.Core/Legality/RNG/Overworld8RNG.cs @@ -22,11 +22,11 @@ public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny var rnd = Util.Rand; do { - var seed = Util.Rand32(rnd); + var seed = rnd.Rand32(); if (TryApplyFromSeed(pk, criteria, shiny, flawless, seed)) return; } while (++ctr != maxAttempts); - TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, Util.Rand32(rnd)); + TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, rnd.Rand32()); } private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed) diff --git a/PKHeX.Core/Legality/RNG/PIDGenerator.cs b/PKHeX.Core/Legality/RNG/PIDGenerator.cs index c772711cb..983bedcfb 100644 --- a/PKHeX.Core/Legality/RNG/PIDGenerator.cs +++ b/PKHeX.Core/Legality/RNG/PIDGenerator.cs @@ -219,9 +219,10 @@ public static void SetRandomChainShinyPID(PKM pk, uint seed) public static void SetRandomPokeSpotPID(PKM pk, int nature, int gender, int ability, int slot) { + var rnd = Util.Rand; while (true) { - var seed = Util.Rand32(); + var seed = rnd.Rand32(); if (!MethodFinder.IsPokeSpotActivation(slot, seed, out _)) continue; @@ -341,9 +342,10 @@ private static void SetRandomWildPID4(PKM pk, int nature, int ability, int gende var type = GetPIDType(pk, specific); var method = GetGeneratorMethod(type); + var rnd = Util.Rand; while (true) { - method(pk, Util.Rand32()); + method(pk, rnd.Rand32()); if (!IsValidCriteria4(pk, nature, ability, gender)) continue; return; @@ -393,9 +395,10 @@ private static void SetRandomWildPID5(PKM pk, int nature, int ability, int gende if (ability == 2) ability = 0; + var rnd = Util.Rand; while (true) { - uint seed = Util.Rand32(); + uint seed = rnd.Rand32(); if (specific == PIDType.G5MGShiny) { SetValuesFromSeedMG5Shiny(pk, seed); @@ -422,8 +425,7 @@ private static void SetRandomWildPID5(PKM pk, int nature, int ability, int gende private static void SetRandomWildPID(PKM pk, int nature, int ability, int gender) { - uint seed = Util.Rand32(); - pk.PID = seed; + pk.PID = Util.Rand32(); pk.Nature = nature; pk.Gender = gender; pk.RefreshAbility(ability); diff --git a/PKHeX.Core/Legality/RNG/Roaming8bRNG.cs b/PKHeX.Core/Legality/RNG/Roaming8bRNG.cs index e52097e87..b8ede8ef2 100644 --- a/PKHeX.Core/Legality/RNG/Roaming8bRNG.cs +++ b/PKHeX.Core/Legality/RNG/Roaming8bRNG.cs @@ -24,13 +24,13 @@ public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny var rnd = Util.Rand; do { - var seed = Util.Rand32(rnd); + var seed = rnd.Rand32(); if (seed == int.MaxValue) continue; // Unity's Rand is [int.MinValue, int.MaxValue) if (TryApplyFromSeed(pk, criteria, shiny, flawless, seed)) return; } while (++ctr != maxAttempts); - TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, Util.Rand32(rnd)); + TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, rnd.Rand32()); } private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed) diff --git a/PKHeX.Core/Legality/RNG/Wild8bRNG.cs b/PKHeX.Core/Legality/RNG/Wild8bRNG.cs index 08f9be479..5071b816a 100644 --- a/PKHeX.Core/Legality/RNG/Wild8bRNG.cs +++ b/PKHeX.Core/Legality/RNG/Wild8bRNG.cs @@ -24,16 +24,16 @@ public static class Wild8bRNG var rnd = Util.Rand; do { - ulong s0 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32; - ulong s1 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32; + ulong s0 = rnd.Rand64(); + ulong s1 = rnd.Rand64(); var xors = new XorShift128(s0, s1); if (TryApplyFromSeed(pk, criteria, shiny, flawless, xors, ability)) return; } while (++ctr != maxAttempts); { - ulong s0 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32; - ulong s1 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32; + ulong s0 = rnd.Rand64(); + ulong s1 = rnd.Rand64(); var xors = new XorShift128(s0, s1); TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, xors, ability); } diff --git a/PKHeX.Core/MysteryGifts/PGF.cs b/PKHeX.Core/MysteryGifts/PGF.cs index edc1aaa51..8f3c0607e 100644 --- a/PKHeX.Core/MysteryGifts/PGF.cs +++ b/PKHeX.Core/MysteryGifts/PGF.cs @@ -318,9 +318,9 @@ private void SetPID(PKM pk, int av) return; } - pk.PID = Util.Rand32(); - // Force Gender var rnd = Util.Rand; + pk.PID = rnd.Rand32(); + // Force Gender do { pk.PID = (pk.PID & 0xFFFFFF00) | (uint)rnd.Next(0x100); } while (!pk.IsGenderValid()); diff --git a/PKHeX.Core/PKM/PK1.cs b/PKHeX.Core/PKM/PK1.cs index bb5c29f84..35f1ec42e 100644 --- a/PKHeX.Core/PKM/PK1.cs +++ b/PKHeX.Core/PKM/PK1.cs @@ -157,16 +157,17 @@ public PK2 ConvertToPK2() public PK7 ConvertToPK7() { + var rnd = Util.Rand; var pk7 = new PK7 { - EncryptionConstant = Util.Rand32(), + EncryptionConstant = rnd.Rand32(), Species = Species, TID = TID, CurrentLevel = CurrentLevel, EXP = EXP, Met_Level = CurrentLevel, Nature = Experience.GetNatureVC(EXP), - PID = Util.Rand32(), + PID = rnd.Rand32(), Ball = 4, MetDate = DateTime.Now, Version = (int)GameVersion.RD, // Default to red @@ -200,7 +201,6 @@ public PK7 ConvertToPK7() // IVs Span finalIVs = stackalloc int[6]; int flawless = Species == (int)Core.Species.Mew ? 5 : 3; - var rnd = Util.Rand; for (var i = 0; i < finalIVs.Length; i++) finalIVs[i] = rnd.Next(32); for (var i = 0; i < flawless; i++) diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index a21a2e2e4..067f6bc35 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -131,16 +131,17 @@ public PK1 ConvertToPK1() public PK7 ConvertToPK7() { + var rnd = Util.Rand; var pk7 = new PK7 { - EncryptionConstant = Util.Rand32(), + EncryptionConstant = rnd.Rand32(), Species = Species, TID = TID, CurrentLevel = CurrentLevel, EXP = EXP, Met_Level = CurrentLevel, Nature = Experience.GetNatureVC(EXP), - PID = Util.Rand32(), + PID = rnd.Rand32(), Ball = 4, MetDate = DateTime.Now, Version = HasOriginalMetLocation ? (int)GameVersion.C : (int)GameVersion.SI, @@ -172,7 +173,6 @@ public PK7 ConvertToPK7() var special = Species is 151 or 251; Span finalIVs = stackalloc int[6]; int flawless = special ? 5 : 3; - var rnd = Util.Rand; for (var i = 0; i < finalIVs.Length; i++) finalIVs[i] = rnd.Next(32); for (var i = 0; i < flawless; i++) diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 319365f60..7c1f84b0c 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -944,7 +944,7 @@ public void SetPIDNature(int nature) public void SetPIDUnown3(int form) { var rnd = Util.Rand; - do PID = Util.Rand32(rnd); while (PKX.GetUnownForm(PID) != form); + do PID = rnd.Rand32(); while (PKX.GetUnownForm(PID) != form); if (Format >= 6 && (Gen3 || Gen4 || Gen5)) EncryptionConstant = PID; } diff --git a/PKHeX.Core/PKM/Shared/G3PKM.cs b/PKHeX.Core/PKM/Shared/G3PKM.cs index 745a74e13..9caf58868 100644 --- a/PKHeX.Core/PKM/Shared/G3PKM.cs +++ b/PKHeX.Core/PKM/Shared/G3PKM.cs @@ -46,7 +46,7 @@ public sealed override int Form return; var rnd = Util.Rand; while (PKX.GetUnownForm(PID) != value) - PID = Util.Rand32(rnd); + PID = rnd.Rand32(); } } diff --git a/PKHeX.Core/PKM/Util/PKX.cs b/PKHeX.Core/PKM/Util/PKX.cs index 37905f4e5..7c9f99a96 100644 --- a/PKHeX.Core/PKM/Util/PKX.cs +++ b/PKHeX.Core/PKM/Util/PKX.cs @@ -124,7 +124,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin, { // Gen6+ (and VC) PIDs do not tie PID to Nature/Gender/Ability if (origin >= 24) - return Util.Rand32(rnd); + return rnd.Rand32(); // Below logic handles Gen3-5. @@ -136,7 +136,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin, bool singleGender = PersonalInfo.IsSingleGender(gt); // single gender, skip gender check while (true) // Loop until we find a suitable PID { - uint pid = Util.Rand32(rnd); + uint pid = rnd.Rand32(); // Gen 3/4: Nature derived from PID if (g34 && pid%25 != nature) diff --git a/PKHeX.Core/Saves/Substructures/Gen7/LGPE/GP1.cs b/PKHeX.Core/Saves/Substructures/Gen7/LGPE/GP1.cs index 4a3fbaf97..4833f63c3 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/LGPE/GP1.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/LGPE/GP1.cs @@ -141,8 +141,11 @@ public string FileNameWithoutExtension public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria) { + var rnd = Util.Rand; var pk = new PB7 { + EncryptionConstant = rnd.Rand32(), + PID = rnd.Rand32(), Version = (int) GameVersion.GO, Species = Species, Form = Form, @@ -157,7 +160,6 @@ public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria) OT_Name = sav.OT, Ball = 4, Language = sav.Language, - PID = Util.Rand32(), }; var nick = Nickname; @@ -198,7 +200,6 @@ public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria) pk.AwakeningSetAllTo(2); pk.ResetCalculatedValues(); - pk.SetRandomEC(); return pk; } }