using System;
using System.Runtime.CompilerServices;
namespace PKHeX.Core
{
public static class RNGUtil
{
///
/// Generates an IV for each RNG call using the top 5 bits of frame seeds.
///
/// RNG to use
/// RNG seed
/// Expected IVs
/// True if all match.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool GetSequentialIVsUInt32(this LCRNG rng, uint seed, ReadOnlySpan IVs)
{
foreach (var iv in IVs)
{
seed = rng.Next(seed);
var IV = seed >> 27;
if (IV != iv)
return false;
}
return true;
}
///
/// Generates an IV for each RNG call using the top 5 bits of frame seeds.
///
/// RNG to use
/// RNG seed
/// Buffer to store generated values
/// Array of 6 IVs as .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void GetSequentialIVsInt32(this LCRNG rng, uint seed, Span ivs)
{
for (int i = 0; i < 6; i++)
{
seed = rng.Next(seed);
ivs[i] = (int)(seed >> 27);
}
}
}
}