Skip to content

Commit

Permalink
modulo iteration util
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed May 31, 2018
1 parent 2fc389a commit d386af2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions math/MathUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;


namespace g3
Expand Down Expand Up @@ -643,5 +644,20 @@ public static int PowerOf10(int n) {
}


/// <summary>
/// Iterate from 0 to (nMax-1) using prime-modulo, so we see every index once, but not in-order
/// </summary>
public static IEnumerable<int> ModuloIteration(int nMaxExclusive, int nPrime = 31337)
{
int i = 0;
bool done = false;
while (done == false) {
yield return i;
i = (i + nPrime) % nMaxExclusive;
done = (i == 0);
}
}


}
}

0 comments on commit d386af2

Please sign in to comment.