How phellipeandrade/random-weighted-pick works
random-weighted-pick is a dependency-free TypeScript library for sampling items in proportion to their weights. A consumer imports its public API and chooses a single pick, a batch (with or without replacement), or a reusable picker using CDF or alias sampling. The implementation validates options, normalizes weights, and draws randomness through an injectable or default RNG. The README documents these capabilities; the sampled source shows their implementation in src/weightList.ts.
Main entry points: index.ts Exported API · weightList.ts Batch pick
Components 7
Public API
- Exported API
src/index.ts
Sampling operations
- Single pick
src/weightList.ts - Batch pick
src/weightList.ts - Reusable picker
src/weightList.ts
Sampling internals
- Validation and weights
src/weightList.ts - Random draws
src/weightList.ts
Other components
- Library consumer
Connections 11
- Library consumer → Exported API: imports
README.md - Exported API → Single pick: exports
src/index.ts - Exported API → Batch pick: exports
src/index.ts - Exported API → Reusable picker: exports
src/index.ts - Batch pick → Single pick: repeats
src/weightList.ts - Single pick → Validation and weights: validates and normalizes
src/weightList.ts - Single pick → Random draws: draws from
src/weightList.ts - Batch pick → Validation and weights: validates options
src/weightList.ts - Batch pick → Random draws: draws from
src/weightList.ts - Reusable picker → Validation and weights: builds distributions
src/weightList.ts - Reusable picker → Random draws: draws from
src/weightList.ts