npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

stochast

v0.0.1

Published

Stochastic utilities: distributions, sampling, statistics, information theory, Markov chains, bootstrap, Monte Carlo. Zero dependencies.

Downloads

134

Readme

Table of Contents

Install

npm install stochast

Modules

Distributions

import {
  uniformRand,
  randInt,
  bernoulliRand,
  exponentialRand,
  poissonRand,
  binomialRand,
  gaussianRand,
  gaussianRandWith,
  lognormalRand,
  cauchyRand,
} from "stochast";

uniformRand(0, 1); // [0, 1)
randInt(1, 6); // 1–6 inclusive
bernoulliRand(0.7); // true/false with 70% chance
exponentialRand(2.0); // mean = 0.5
poissonRand(5.0); // mean = 5
binomialRand(10, 0.5); // 0–10
gaussianRand(); // mean 0, stddev 1
gaussianRandWith(100, 15); // custom mean/stddev
lognormalRand(0, 0.5); // always positive
cauchyRand(0, 1); // heavy-tailed

Sampling

import { shuffle, sample, sampleWithReplacement, randomPick, weightedPick } from "stochast";

shuffle([1, 2, 3]); // new shuffled array
sample([1, 2, 3, 4, 5], 3); // 3 unique items
sampleWithReplacement([1, 2], 5); // 5 items, duplicates OK
randomPick(["a", "b", "c"]); // single random item
weightedPick(items, (i) => i.weight); // weighted random

Statistics

import { mean, median, standardDeviation, variance, percentile, zScore, clamp } from "stochast";

mean([1, 2, 3, 4, 5]); // 3
median([3, 1, 2]); // 2
standardDeviation([1, 2, 3]); // ~0.816
variance([1, 2, 3, 4, 5]); // 2
percentile([1, 2, 3, 4, 5], 50); // 3
zScore(5, [1, 2, 3, 4, 5]); // ~1.414
clamp(15, 0, 10); // 10

Hashing

import { hashString, hashToRange, hashToFloat, fnv1a, deterministicLineCount } from "stochast";

hashString("hello"); // deterministic integer
hashToRange("test", 0, 100); // 0–100
hashToFloat("test"); // [0, 1)
fnv1a("hello"); // FNV-1a hash
deterministicLineCount("src/index.ts", false); // 120–2800

Smoothing

import { ema, emaSeries, sma } from "stochast";

ema(0.5, 1.0, 0.3); // 0.65
emaSeries([1, 2, 3, 4, 5], 0.5); // smoothed series
sma([1, 2, 3, 4, 5], 3); // simple moving average

Markov Chains

import { buildMatrix, sampleSequence, stationaryDistribution, nextState } from "stochast";

const matrix = buildMatrix(["A", "B", "A", "C", "A", "B"]);
const seq = sampleSequence(matrix, "A", 10); // 10-state sequence
const dist = stationaryDistribution(matrix); // long-run probabilities

Bootstrap

import { bootstrapCI, bootstrapSE, permutationTest, resample } from "stochast";

const [lo, hi] = bootstrapCI(data, mean); // 95% CI for mean
const se = bootstrapSE(data, standardDeviation); // standard error
const p = permutationTest(groupA, groupB, mean); // permutation p-value

Information Theory

import { entropy, klDivergence, jsDivergence, mutualInformation, giniImpurity } from "stochast";

entropy([0.5, 0.5]); // ln(2) ≈ 0.693
klDivergence(p, q); // D_KL(p || q)
jsDivergence(p, q); // symmetric divergence
mutualInformation(joint, margX, margY); // I(X; Y)
giniImpurity([0.5, 0.5]); // 0.5

Advanced Sampling

import { inverseTransform, acceptReject, poissonProcess, weightedResample } from "stochast";

inverseTransform(cdf, 0, 10); // sample from CDF
acceptReject(proposal, pdf, propPdf, M); // accept-reject
poissonProcess(2.0, 100); // event times in [0, 100)
weightedResample([0.1, 0.3, 0.6], 100); // weighted indices

Monte Carlo

import { monteCarloIntegral, monteCarloExpectation, buffonsNeedle, randomWalk, brownianMotion } from "stochast";

monteCarloIntegral((x) => x * x, 0, 1); // ≈ 1/3
monteCarloExpectation(gaussianRand, (x) => x * x); // ≈ 1
buffonsNeedle(1, 2, 10000); // ≈ pi
randomWalk(100, 1, 2); // 2D random walk
brownianMotion(1000, 0.01, 1); // Brownian path

Note

THIS IS A GENERAL-PURPOSE STOCHASTIC UTILITIES LIBRARY. IT DOES NOT TARGET ANY SPECIFIC DOMAIN. IT PROVIDES PURE, COMPOSABLE PRIMITIVES FOR RANDOMNESS, SAMPLING, AND STATISTICAL ESTIMATION. IF YOU NEED DOMAIN-SPECIFIC LOGIC, BUILD ON TOP OF THESE FUNCTIONS.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this software.