Inline some Rand32 calls

No functional change
This commit is contained in:
Kurt 2022-04-26 20:21:26 -07:00
parent b55d706785
commit fa76da56c9
12 changed files with 32 additions and 28 deletions

View file

@ -38,7 +38,8 @@
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;
}

View file

@ -22,11 +22,11 @@ namespace PKHeX.Core
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)

View file

@ -219,9 +219,10 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
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);

View file

@ -24,13 +24,13 @@ namespace PKHeX.Core
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)

View file

@ -24,16 +24,16 @@ namespace PKHeX.Core
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);
}

View file

@ -318,9 +318,9 @@ namespace PKHeX.Core
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());

View file

@ -157,16 +157,17 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
// IVs
Span<int> 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++)

View file

@ -131,16 +131,17 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
var special = Species is 151 or 251;
Span<int> 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++)

View file

@ -944,7 +944,7 @@ namespace PKHeX.Core
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;
}

View file

@ -46,7 +46,7 @@
return;
var rnd = Util.Rand;
while (PKX.GetUnownForm(PID) != value)
PID = Util.Rand32(rnd);
PID = rnd.Rand32();
}
}

View file

@ -124,7 +124,7 @@ namespace PKHeX.Core
{
// 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 @@ namespace PKHeX.Core
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)

View file

@ -141,8 +141,11 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
OT_Name = sav.OT,
Ball = 4,
Language = sav.Language,
PID = Util.Rand32(),
};
var nick = Nickname;
@ -198,7 +200,6 @@ namespace PKHeX.Core
pk.AwakeningSetAllTo(2);
pk.ResetCalculatedValues();
pk.SetRandomEC();
return pk;
}
}