# hbprng

> Hash-Based Pseudo-Random Number Generator

Latest version **0.1.1** (published 2017-09-21) · LGPL-3.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-09-21 |
| First published | 2017-09-18 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Charles Pascoe |
| Maintainers | cpascoe95 |

## Links

- npm: https://www.npmjs.com/package/hbprng
- Repository: https://github.com/cpascoe95/hbprng
- Homepage: https://github.com/cpascoe95/hbprng#readme
- Issues: https://github.com/cpascoe95/hbprng/issues
- npm.io page: https://npm.io/package/hbprng

## Recent versions

- 0.1.1 (latest) — 2017-09-21
- 0.1.0 — 2017-09-18
- 0.0.1 — 2017-09-18

## README

# Hash-Based Pseudo-Random Number Generator

A deterministic number generator based on cryptographic hashing algorithms, with TypeScript typings.

## Installation

`$ npm install hbprng`

## Usage

```ts
import { Hbprng } from 'hbprng';

let generator = new Hbprng(Buffer.from('seed', 'utf8'), 'sha512');

console.log(generator.nextInt());
console.log(generator.nextInt());
console.log(generator.nextInt());

// Output:
// 3242175261
// 539230564
// 526738857
```

## Hbprng Class API

### constructor(seed: Buffer, [hashAlg: string = 'sha256'])

- `seed`: a `Buffer` used to initialise the number generator
- `hashAlg`: a `string` representing the hashing algorithm used to derive the sequence. Defaults to `sha256`. Please see the [Node Crypto Docs](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options) for more information on available hashing algorithms.

Given the same `seed` and `hashAlg`, the generator will produce the same sequence.

### nextByte(): number

Returns the next byte from the sequence.

### nextInt(): number

Returns the next 32-bit unsigned integer from the sequence. Note that this method moves 4 bytes along the sequence.

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