We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2fc389a commit d386af2Copy full SHA for d386af2
math/MathUtil.cs
@@ -1,4 +1,5 @@
1
using System;
2
+using System.Collections.Generic;
3
4
5
namespace g3
@@ -643,5 +644,20 @@ public static int PowerOf10(int n) {
643
644
}
645
646
647
+ /// <summary>
648
+ /// Iterate from 0 to (nMax-1) using prime-modulo, so we see every index once, but not in-order
649
+ /// </summary>
650
+ public static IEnumerable<int> ModuloIteration(int nMaxExclusive, int nPrime = 31337)
651
+ {
652
+ int i = 0;
653
+ bool done = false;
654
+ while (done == false) {
655
+ yield return i;
656
+ i = (i + nPrime) % nMaxExclusive;
657
+ done = (i == 0);
658
+ }
659
660
+
661
662
663
0 commit comments