# secure-chance

> Create an instance of Chance with a truly random seed.

Latest version **2.0.0** (published 2020-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install secure-chance
pnpm add secure-chance
yarn add secure-chance
bun add secure-chance
```

## 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 | 2.0.0 |
| Published | 2020-10-05 |
| First published | 2019-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.17 |
| Dependencies | 2 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Richie Bendall |
| Maintainers | richienb |
| Keywords | chance, secure, crypto, quantum, math, random |

## Links

- npm: https://www.npmjs.com/package/secure-chance
- Repository: https://github.com/Richienb/secure-chance
- npm.io page: https://npm.io/package/secure-chance

## Dependencies (2)

- [math-random](https://npm.io/package/math-random.md) ^2.0.1
- [quantum-random](https://npm.io/package/quantum-random.md) ^1.0.0

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-10-05
- 1.1.1 — 2019-11-29
- 1.1.0 — 2019-11-26
- 1.0.2 — 2019-11-03
- 1.0.1 — 2019-10-19
- 1.0.0 — 2019-10-18
- 0.0.0 — 2019-10-17

## README

# secure-chance [![Travis CI Build Status](https://img.shields.io/travis/com/Richienb/secure-chance/master.svg?style=for-the-badge)](https://travis-ci.com/Richienb/secure-chance)

Create an instance of [Chance](https://github.com/chancejs/chancejs) with a truly random seed.

[![NPM Badge](https://nodei.co/npm/secure-chance.png)](https://npmjs.com/package/secure-chance)

## Install

```sh
npm install secure-chance
```

## Why

[Chance](https://github.com/chancejs/chancejs) currently uses a [Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_Twister) seeded by `Math.random()` for randomness.

The problem with this is that `Math.random()` [is not cryptographically secure](https://security.stackexchange.com/questions/84906/predicting-math-random-numbers/110241#110241) as it was never required in the [specification](https://tc39.es/ecma262/#sec-math.random).

`secure-chance` fixes this issue by generating a random seed using quantum randomness provided by [qrng.anu.edu.au](https://qrng.anu.edu.au) with a fallback to secure offline methods like the [Node.js Crypto API](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback) or the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues).

## Usage

```js
const secureChance = require("secure-chance")
const chance = await secureChance()

chance.integer({ min: -20, max: 20 })
chance.string({ length: 5 })
```

## API

### secureChance()

Returns a promise which resolves with an instance of [Chance](https://chancejs.com).

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