# phellipeandrade/random-weighted-pick architecture

> Architecture diagram of the GitHub repository phellipeandrade/random-weighted-pick, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phellipeandrade/random-weighted-pick
- Repository: https://github.com/phellipeandrade/random-weighted-pick

## Overview

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: [`src/index.ts`](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/index.ts) (Exported API), [`src/weightList.ts`](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts) (Batch pick)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Public API"]
  node_api["Exported API<br/>[index.ts]"]
end

subgraph group_sampling["Sampling operations"]
  node_single["Single pick<br/>[weightList.ts]"]
  node_batch["Batch pick<br/>[weightList.ts]"]
  node_picker["Reusable picker<br/>[weightList.ts]"]
end

subgraph group_internals["Sampling internals"]
  node_prep["Validation and weights<br/>[weightList.ts]"]
  node_rng["Random draws<br/>[weightList.ts]"]
end

node_consumer(("Library consumer"))

node_consumer -->|"imports"| node_api
node_api -->|"exports"| node_single
node_api -->|"exports"| node_batch
node_api -->|"exports"| node_picker
node_batch -->|"repeats"| node_single
node_single -->|"validates and normalizes"| node_prep
node_single -->|"draws from"| node_rng
node_batch -->|"validates options"| node_prep
node_batch -->|"draws from"| node_rng
node_picker -->|"builds distributions"| node_prep
node_picker -->|"draws from"| node_rng

click node_api "https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/index.ts"
click node_single "https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts"
click node_batch "https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts"
click node_picker "https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts"
click node_prep "https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts"
click node_rng "https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api toneBlue
class node_single,node_batch,node_picker toneAmber
class node_prep,node_rng toneMint
class node_consumer toneIndigo
```

## Components

### Public API

- [Exported API](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/index.ts): `src/index.ts`

### Sampling operations

- [Single pick](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts): `src/weightList.ts`
- [Batch pick](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts): `src/weightList.ts`
- [Reusable picker](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts): `src/weightList.ts`

### Sampling internals

- [Validation and weights](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts): `src/weightList.ts`
- [Random draws](https://github.com/phellipeandrade/random-weighted-pick/blob/master/src/weightList.ts): `src/weightList.ts`

### Other components

- **Library consumer**

## Connections

- Library consumer → Exported API: imports (evidence: `README.md`)
- Exported API → Single pick: exports (evidence: `src/index.ts`)
- Exported API → Batch pick: exports (evidence: `src/index.ts`)
- Exported API → Reusable picker: exports (evidence: `src/index.ts`)
- Batch pick → Single pick: repeats (evidence: `src/weightList.ts`)
- Single pick → Validation and weights: validates and normalizes (evidence: `src/weightList.ts`)
- Single pick → Random draws: draws from (evidence: `src/weightList.ts`)
- Batch pick → Validation and weights: validates options (evidence: `src/weightList.ts`)
- Batch pick → Random draws: draws from (evidence: `src/weightList.ts`)
- Reusable picker → Validation and weights: builds distributions (evidence: `src/weightList.ts`)
- Reusable picker → Random draws: draws from (evidence: `src/weightList.ts`)
