# randchacha

> The ChaCha random number generator.

Latest version **1.0.2** (published 2021-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install randchacha
pnpm add randchacha
yarn add randchacha
bun add randchacha
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-08-23 |
| First published | 2021-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 427.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Ian Coleman |
| Maintainers | iancoleman |

## Links

- npm: https://www.npmjs.com/package/randchacha
- Repository: https://github.com/iancoleman/randchacha-js
- Issues: https://github.com/iancoleman/randchacha-js/issues
- npm.io page: https://npm.io/package/randchacha

## Dependencies (1)

- [chacha](https://npm.io/package/chacha.md) ^2.1.0

## Recent versions

- 1.0.2 (latest) — 2021-08-23
- 1.0.1 — 2021-08-21
- 1.0.0 — 2021-08-21

## README

# randChaCha

The ChaCha random number generator.

Inspired by and compatible with rust crate
[rand_chacha](https://rust-random.github.io/rand/rand_chacha/)

# Usage

## Node

```
npm install --save randchacha
```

```
rcc = require("randchacha")

// seed must be 32 bytes
seed0 = new Uint8Array(32)

// create a new rng from the seed
rng1 = new rcc.ChaChaRng(seed0)

// nextU32 returns a number
randNumber = rng1.nextU32()

// nextU64 returns a BigInt
randBigint = rng1.nextU64()

// fillBytes will update the input (like crypto.getRandomValues)
randBytes = new Uint832Array(100)
rng1.fillBytes(randBytes);

// can create multiple generators
rng2 = new rcc.ChaChaRng(seed0)

// the same seed produces the same sequence of numbers
randNumber2 = rng2.nextU32()

// a different seed produces a different sequence of numbers
seed55 = new Uint8Array(32)
seed55[0] = 55
rng3 = new rcc.ChaChaRng(seed55)

rng3.nextU32() // not equal to randNumber
```

## Browser

Use randchacha_browser.js

```
<script src="randchacha_browser.js"></script>
```

```
let seed = new Uint8Array(32);
let rng = new randchacha.ChaChaRng(seed);
rng.nextU32();
// see nodejs usage for full details
```

# Tests

To run tests

```
cd /path/to/randchacha
npm install --include=dev
npm run test
```

---
_Source: https://npm.io/package/randchacha · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
