mirror of
https://github.com/kwsch/pkNX.git
synced 2026-08-26 04:20:28 -05:00
Initial Commit
This commit is contained in:
34
pkNX.Randomization/Randomizers/GenericRandomizer.cs
Normal file
34
pkNX.Randomization/Randomizers/GenericRandomizer.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user