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

Commit

Permalink
Warn if constrained shuffle exceeds the maximum iteration number
Browse files Browse the repository at this point in the history
  • Loading branch information
dgfitch authored and FelixHenninger committed Aug 17, 2020
1 parent 463efd7 commit 66bd2d1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/library/src/util/random/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 66bd2d1

Please sign in to comment.