als-statistics
Version:
Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co
19 lines (17 loc) • 527 B
JavaScript
import seedrandom from 'seedrandom';
export function makeRng(seed) {
const rng = seedrandom(seed);
function boxMuller() {
let u = 0, v = 0;
while (u === 0) u = rng();
while (v === 0) v = rng();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
return {
rand: () => rng(),
normal: (mu=0, sigma=1, n=20) =>
Array.from({length:n}, () => mu + sigma * boxMuller()),
uniform: (a=0, b=1, n=20) =>
Array.from({length:n}, () => a + (b-a)*rng()),
};
}