diff --git a/src/array.js b/src/array.js index d83970a0..81723dac 100644 --- a/src/array.js +++ b/src/array.js @@ -1,19 +1,23 @@ -import lcg from "./lcg.js"; - export default function(x) { return typeof x === "object" && "length" in x ? x // Array, TypedArray, NodeList, array-like : Array.from(x); // Map, Set, iterable, string, or anything else } +// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use +const a = 1664525; +const c = 1013904223; +const mm = 4294967296; // 2^32 + export function shuffle(array) { - const random = lcg(); + let s = 1; let m = array.length, t, i; while (m) { - i = random() * m-- | 0; + s = (a * s + c) % mm; + i = s / mm * m-- | 0; t = array[m]; array[m] = array[i]; array[i] = t; diff --git a/src/lcg.js b/src/lcg.js deleted file mode 100644 index a13cf79e..00000000 --- a/src/lcg.js +++ /dev/null @@ -1,9 +0,0 @@ -// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use -const a = 1664525; -const c = 1013904223; -const m = 4294967296; // 2^32 - -export default function() { - let s = 1; - return () => (s = (a * s + c) % m) / m; -}