A Haxe random library that compiles to JavaScript, published to npm (and haxelib).
| Export | Description |
|---|---|
Rng |
Seedable PRNG (xorshift128+ via seedyrng). Same seed → same sequence. |
poisson.Sampler |
Bridson-style Poisson-disc sampler — even blue-noise point distributions. |
poisson.RandomSampler |
Dart-throwing Poisson-disc sampler — good for incremental getNewPoints. |
poisson.MultiSampler |
A grid of sub-samplers for large / effectively unbounded spaces. |
poisson.Point |
Simple 2D point with distanceTo. |
lds.VanDerCorput |
1D Van der Corput low-discrepancy sequence. |
lds.Halton |
N-D Halton low-discrepancy sequence (quasi-random points). |
loot.WeightedSelector |
Generic weighted random selector (roulette-wheel), backed by Rng. |
loot.LootTable |
Named pools of weighted items (generic <T>) — roll loot by type. |
curve.Curve |
Easing-shaped value sampler with windowed random variance (uses dropecho.easings). |
import { Rng, poisson, lds, loot, curve, easings } from "@dropecho/random";
const rng = new Rng(1234);
rng.random(); // [0, 1)
rng.range(5, 10); // [5, 10)
const points = new poisson.Sampler(256, 256, 16).getPoints();
const halton = new lds.Halton([2, 3]);
halton.getNext(); // [0, 0], then [0.5, 0.333...], ...
const sel = new loot.WeightedSelector(rng);
sel.add("common", 70).add("rare", 25).add("legendary", 5);
sel.pick(); // weighted by share of the total
const table = new loot.LootTable(rng);
table.add("chest", "gold", 10).add("chest", "gem", 1);
table.getItem("chest"); // "gold" ~10x as often as "gem"
const c = new curve.Curve(rng, easings.easeInQuad, { positiveVar: 0.2 });
c.sample(0.5); // eased ~0.25, jittered upward by up to 0.2| Target | Output | Status |
|---|---|---|
| JS (CommonJS) | dist/js/cjs/index.cjs |
on by default |
JS (ES module + .d.ts) |
dist/js/esm/index.js |
on by default |
| API docs (dox XML) | artifacts/docs.xml |
commented in build.hxml |
npm install # fetch pinned Haxe + libs via lix (runs `lix download`)
npm run build # build the enabled targets (haxe build.hxml)
npm test # run the utest suite via dropecho.testing (lix dropecho.testing)
npm run clean # remove dist/ and artifacts/- Dependencies are managed by lix (a
devDependency, so no global install is needed): the Haxe version is pinned in.haxercand each lib inhaxe_libraries/.npm installinstalls lix, then runslix downloadto materialize them. - Build options are split into shared settings (top of
build.hxml) and one hxml per target undertargets/. Enable a target by uncommenting its--next targets/<name>.hxmlpair. - Tests are auto-discovered: every
test/**/*Tests.hxclass thatextends utest.Testis registered bydropecho.testing— there is no test main to maintain. The suite runs on the JS (Node) target.
The CommonJS and ESM builds are wired up through package.json exports, so the package
works for both require and import. The ESM build also emits .d.ts typings via genes.
Releases are automated with semantic-release (see .releaserc.json): commits drive the
version bump, and the package is published to npm and haxelib with a generated changelog.
MIT