diff --git a/Rotationator/Program.cs b/Rotationator/Program.cs index 63a45b2..c767aa7 100644 --- a/Rotationator/Program.cs +++ b/Rotationator/Program.cs @@ -1,4 +1,4 @@ -using System.CommandLine; +using System.CommandLine; using System.CommandLine.Invocation; using System.Text.Json; using OatmealDome.BinaryData; @@ -323,10 +323,18 @@ void Run(InvocationContext context) T GetRandomElementFromPool(List pool, Func validityChecker) { T element; + int tries = 0; do { element = pool[random.Next(0, pool.Count)]; + + tries++; + + if (tries > 10000) + { + throw new Exception("Possible infinite loop detected in GetRandomElementFromPool"); + } } while (!validityChecker(element)); pool.Remove(element);