pk3DS/pk3DS.Core/Randomizers/GenericRandomizer.cs
Kurt fa5bdee781 Refactoring
use new randomization objects in other forms
re-standardize namespaces a little
2017-09-09 22:16:55 -07:00

35 lines
851 B
C#

namespace pk3DS.Core.Randomizers
{
/// <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 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;
}
}
}