# fn-pcg

> A functional typescript implementation of the PCG family random number generators

Latest version **2.0.1** (published 2023-04-22) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install fn-pcg
pnpm add fn-pcg
yarn add fn-pcg
bun add fn-pcg
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-04-22 |
| First published | 2022-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Kristóf Poduszló |
| Maintainers | philihp |

## Links

- npm: https://www.npmjs.com/package/fn-pcg
- Repository: https://github.com/philihp/fn-pcg
- Homepage: https://github.com/philihp/fn-pcg#readme
- Issues: https://github.com/philihp/fn-pcg/issues
- npm.io page: https://npm.io/package/fn-pcg

## Dependencies (2)

- [long](https://npm.io/package/long.md) 5.2.3
- [ramda](https://npm.io/package/ramda.md) 0.29.0

## Recent versions

- 2.0.1 (latest) — 2023-04-22
- 2.0.0 — 2023-04-22
- 1.0.1 — 2023-04-19
- 0.2.1 — 2023-04-18
- 0.2.0 — 2023-04-18
- 1.3.0 — 2023-04-18
- 1.2.0 — 2023-02-06
- 1.1.1 — 2023-02-06
- 1.1.0 — 2023-02-06
- 1.0.0 — 2022-12-18

## README

# fn-pcg

[![Version](https://img.shields.io/npm/v/fn-pcg.svg)](https://www.npmjs.com/package/fn-pcg)
[![Tests](https://github.com/philihp/fn-pcg/actions/workflows/tests.yml/badge.svg)](https://github.com/philihp/fn-pcg/actions/workflows/tests.yml)
[![Coverage](https://coveralls.io/repos/github/philihp/fn-pcg/badge.svg?branch=main)](https://coveralls.io/github/philihp/fn-pcg?branch=main)
![Downloads](https://img.shields.io/npm/dt/fn-pcg)
![License](https://img.shields.io/npm/l/fn-pcg)

A functional implementation of the [PCG family random number generators](), written in JavaScript.

[PCG family random number generators]: http://pcg-random.org

## Getting started

To achieve frictionless reproducibility of random output results, immutable objects are used throughout the project.

Firstly, create a random number engine:

```js
import { createPcg32 } from 'pcg'

const advancedOptions = {}
const initState = 42
const initStreamId = 54
const state0 = createPcg32(advancedOptions, initState, initStreamId)
```

After that, random outputs can be generated by calling appropriate functions as shown below:

```js
import { nextState, prevState, randomInt, randomList } from 'pcg'

const randomUint32 = randomInt(0, 2 ** 32 - 1)
const [value, nextState] = randomUint32(state0)

const listLength = 3
const listItemRng = randomUint32
const [[v1, state1], [v2, state2], [v3, state3]] = randomList(listLength, listItemRng, state0)
```

In this above example, `value === v1`, and `nextState === state1`

## Thanks

- [@kripod](https://github.com/kripod/), who wrote the original [`pcg.js`](https://github.com/kripod/pcg.js)

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