New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fair-random

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fair-random

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

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

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.

Keywords

random

FAQs

Package last updated on 09 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts