Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Random<G>

Type parameters

Hierarchy

  • Random

Index

Constructors

constructor

  • new Random(generator: G): Random
  • Parameters

    • generator: G

    Returns Random

Properties

generator

generator: G

Methods

bool

  • bool(): boolean
  • Generates a random boolean

    Returns boolean

chance

  • chance(decimal: number): boolean
  • Returns whether a chance passes, given a decimal number.

    Example: chance(0.1) is a 1/10 chance, chance(0.8) is a 4/5 chance

    Parameters

    • decimal: number

    Returns boolean

choice

  • choice<A>(...from: A): A[number]
  • Chooses a random entry in an array and returns it

    Type parameters

    • A: any[]

    Parameters

    • Rest ...from: A

    Returns A[number]

float

  • float(): number
  • float(max: number): number
  • float(min: number, max: number): number
  • float(range: IRange): number
  • Generates a random number between 0 (inclusive) and 1 (exclusive)

    Returns number

  • Generates a random number between 0 (inclusive) and max (exclusive)

    Parameters

    • max: number

    Returns number

  • Generates a random number between min (inclusive) and max (exclusive)

    Parameters

    • min: number
    • max: number

    Returns number

  • Generates a random number from the given range.

    Parameters

    Returns number

getElement

  • getElement<T>(array: T[]): T
  • Type parameters

    • T

    Parameters

    • array: T[]

    Returns T

int

  • int(max: number): number
  • int(min: number, max: number): number
  • int(range: IRange): number
  • Generates a random integer between 0 (inclusive) and max (exclusive)

    Parameters

    • max: number

    Returns number

  • Generates a random integer between min (inclusive) and max (exclusive)

    Parameters

    • min: number
    • max: number

    Returns number

  • Generates a random integer from the given range.

    Parameters

    Returns number

intInRange

  • intInRange(min: number, max: number): number
  • intInRange(range: IRange): number
  • Generates a random integer between min and max (inclusive)

    Parameters

    • min: number
    • max: number

    Returns number

  • Parameters

    Returns number

percent

  • percent(minChance?: number, chanceOutOf?: number, ceil?: boolean): number
  • Get a percentage for something Returns a number between 1 and 100 (inclusive)

    Parameters

    • Default value minChance: number = 0
    • Default value chanceOutOf: number = 100
    • Default value ceil: boolean = true

    Returns number

shuffle

  • shuffle<T>(array: T[]): T[]
  • Type parameters

    • T

    Parameters

    • array: T[]

    Returns T[]

weightedChoice

  • Returns a random T from the given choices, where each choice is weighted by a number. Higher numbers = higher chance.

    Type parameters

    • T

    Parameters

    Returns T

withGenerator

  • withGenerator<T>(generator: G, execute: () => T): T
  • Type parameters

    • T

    Parameters

    • generator: G
    • execute: () => T
        • (): T
        • Returns T

    Returns T

Generated using TypeDoc