fair-random
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Fair Random

A simple utility to generate random numbers using a provable fair algorithm.

Install

$ npm install fair-random

Usage

import FairRandom from "fair-random";

const fairRandom = new FairRandom("server_seed", "client_seed", 0);

const num1 = fairRandom.random();
//=> 0.5588404021691531

const num2 = fairRandom.random();
//=> 0.569565019570291

API

Class: FairRandom

new FairRandom(serverSeed, clientSeed, nonce)

  • serverSeed string: A secret seed provided by the server.
  • clientSeed string: A seed provided by the client. This allows the client to have an influence on the randomness.
  • nonce number: A number that is incremented with each bet to ensure different outcomes.

Creates a new FairRandom object containing the random method.

fairRandom.random()

  • Returns: number

Returns a number that's greater than or equal to 0 and less than 1. This function utilises the cryptographic hash function HMAC_SHA256 to generate bytes which are then used to generate floats between 0 and 1.

License

This project is licensed under the MIT License.

Package Sidebar

Install

npm i fair-random

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

4.66 kB

Total Files

6

Last publish

Collaborators

  • gabrielmiranda