Skip to content

Commit

Permalink
fix rare bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alex391 committed Oct 3, 2024
1 parent 795637f commit 0fb74e7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ function randnBm() {
while (v === 0) v = Math.random();
let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
num = num / 10.0 + 0.5; // Translate to 0 -> 1
if (num > 1 || num < 0) return randBm() // resample between 0 and 1
return num
if (num > 1 || num < 0) {
// This branch is *really* rare: about one in a million
return randnBm();
}
return num;
}


// Takes in thee colors given as arrays of [r, g, b]
// and returns a color that's between a and c, where b is a midpoint color
// normal controls weather to use a normal distribution, where b is most likely
Expand Down

0 comments on commit 0fb74e7

Please sign in to comment.