Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 66bd2d1

Browse files
dgfitchFelixHenninger
authored andcommitted
Warn if constrained shuffle exceeds the maximum iteration number
1 parent 463efd7 commit 66bd2d1

File tree

1 file changed

+5
-2
lines changed
  • packages/library/src/util/random

1 file changed

+5
-2
lines changed

packages/library/src/util/random/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,14 @@ export class Random {
162162

163163
// Shuffle until a candidate matches the constraints,
164164
// or the maximum number of iterations is reached
165-
let candidate
166-
for (let i = 0; i < maxIterations; i++) {
165+
let candidate, i
166+
for (i = 0; i < maxIterations; i++) {
167167
candidate = this.shuffle(a)
168168
if (constraintChecker(candidate)) break
169169
}
170+
if (i >= maxIterations) {
171+
console.warn(`constrainedShuffle could not find a matching candidate after ${ maxIterations } iterations`)
172+
}
170173
return candidate
171174
}
172175

0 commit comments

Comments
 (0)