Socket
Socket
Sign inDemoInstall

extra-rand

Package Overview
Dependencies
5
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    extra-rand

Yet another random library


Version published
Weekly downloads
515
increased by46.72%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.3.0 (2024-04-18)

⚠ BREAKING CHANGES

    • Removed randomIntByModel, randomIntInclusiveByModel
  • Rewritten randomByModel
    • Rename randomByWeight to randomIndexByWeight
  • CommonJS => ESM
  • It requires Node.js >= v18.17.0

Features

  • add model-related functions (35777f3)

  • export IRandomModel (eeeb5be)

  • replace randomIntByModel, randomIntInclusiveByModel with randomByModel (8ff1f62)

Readme

Source

extra-rand

Yet another random library.

Install

npm install --save extra-rand
# or
yarn add extra-rand

API

random

function random(min: number, max: number): number

The function returns a number in the range [min, max).

randomInt

function randomInt(min: number, max: number): number

The function returns an integer in the range [Math.ceil(min), Math.floor(max)).

randomIntInclusive

function randomIntInclusive(min: number, max: number): number

The function returns an integer in the range [Math.ceil(min), Math.floor(max)].

randomBool

function randomBool(probabilityOfTrue: number): boolean

randomIndexByWeight

function randomIndexByWeight(weights: NonEmptyArray<number>): number

The function returns an index of one of weights.

randomWeighted

interface IWeighted {
  weight: number
}

function randomWeighted<T extends IWeighted>(values: NonEmptyArray<T>): T

randomByWeightModel

type IWeightModel<T> = NonEmptyArray<{
  weight: number
  value: T
}>

function randomByWeightModel<T>(model: IWeightModel<T>): number

randomByModel

enum Type {
  Float
, Integer
, IntegerInclusive
}

type IRandomModel =
| number
| Getter<number>
| {
    type: Type
    min: number
    max: number
  }
| NonEmptyArray<{
    weight: number
    value: IRandomModel
  }>

function randomByModel(model: IRandomModel): number

mapToRange

function mapToRange(
  value: number
, oldMin: number, oldMax: number
, newMin: number, newMax: number
): number

A low-level function helps you to use random number generators other than Math.random().

mapToIndexByWeight

function mapToIndexByWeight(
  value: number
, oldMin: number, oldMax: number
, weights: NonEmptyArray<number>
): number

A low-level function helps you to use random number generators other than Math.random().

Keywords

FAQs

Last updated on 18 Apr 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc