pkNX/pkNX.Randomization/Randomizers/GenericRandomizer.cs
Kurt 15974cd8d8 Make trainer rand work
tfw no fairy moves -> causing STAB fetch loop to hang for Clefairy, lul
2018-11-23 22:08:41 -08:00

36 lines
895 B
C#

namespace pkNX.Randomization
{
/// <summary> Cyclical Shuffled Randomizer </summary>
/// <remarks>
/// The shuffled list is iterated over, and reshuffled when exhausted.
/// The list does not repeat values until the list is exhausted.
/// </remarks>
public class GenericRandomizer
{
public GenericRandomizer(int[] randomValues)
{
RandomValues = randomValues;
}
private readonly int[] RandomValues;
private int ctr;
public int Count => RandomValues.Length;
public void Reset()
{
ctr = 0;
Util.Shuffle(RandomValues);
}
public int Next()
{
if (ctr == 0)
Util.Shuffle(RandomValues);
int value = RandomValues[ctr++];
ctr %= RandomValues.Length;
return value;
}
}
}