From 66bd2d14e45c8e802be5616d241b1213a6e69053 Mon Sep 17 00:00:00 2001 From: Dan Fitch Date: Mon, 17 Aug 2020 13:01:48 -0500 Subject: [PATCH] Warn if constrained shuffle exceeds the maximum iteration number --- packages/library/src/util/random/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/library/src/util/random/index.js b/packages/library/src/util/random/index.js index 085cf6186..a4c093413 100644 --- a/packages/library/src/util/random/index.js +++ b/packages/library/src/util/random/index.js @@ -162,11 +162,14 @@ export class Random { // Shuffle until a candidate matches the constraints, // or the maximum number of iterations is reached - let candidate - for (let i = 0; i < maxIterations; i++) { + let candidate, i + for (i = 0; i < maxIterations; i++) { candidate = this.shuffle(a) if (constraintChecker(candidate)) break } + if (i >= maxIterations) { + console.warn(`constrainedShuffle could not find a matching candidate after ${ maxIterations } iterations`) + } return candidate }