0.3.0 • Published 13 days ago

extra-rand v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
13 days ago

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().

0.3.0

13 days ago

0.2.1

14 days ago

0.2.0

2 months ago

0.1.5

11 months ago

0.1.2

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.1

2 years ago

0.1.0

3 years ago