Skip to content

Commit

Permalink
deterministic prng
Browse files Browse the repository at this point in the history
fixes #121.(maybe)

do we need to expose jiggle(seed) so people could set the seed? (I don't think so)
  • Loading branch information
Fil committed Jul 27, 2020
1 parent 4799bea commit a72cd1f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/jiggle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export default function() {
return (Math.random() - 0.5) * 1e-6;
// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
const a = 1664525,
c = 1013904223,
m = 4294967296;
let s = 1;
export default function(seed) {
return (s = seed || (a * s + c) % m) / m * 1e-6;
}

0 comments on commit a72cd1f

Please # to comment.