Home Reference Source Repository
import {Random} from 'webgame-lib/src/random.js'
public class | source

Random

You can directly use instance of this class. random

A seeded random generator.

Constructor Summary

Public Constructor
public

Initializes with the seed.

Member Summary

Public Members
public

Current seed.

Method Summary

Public Methods
public

choice(bias: number, exp: number): boolean

Generates a random boolean value accounting for the bias and exponent.

public

Generates a random color string.

public

Generates a string of random letters.

public

Generates next random number in sequence.

public

Generates a random float in the specified range.

public

Generates a random integer in the specified range.

public

select(items: Array): Object

Selects a random element in the supplied collection.

Public Constructors

public constructor(seed: number) source

Initializes with the seed.

Params:

NameTypeAttributeDescription
seed number

Initial seed value

Public Members

public s: number source

Current seed.

Public Methods

public choice(bias: number, exp: number): boolean source

Generates a random boolean value accounting for the bias and exponent.

Params:

NameTypeAttributeDescription
bias number

A positive number to stack odds

exp number

Power to which bias is raised

Return:

boolean

Random choice

public color(): string source

Generates a random color string.

Return:

string

Color in rgb() format

public letters(n: number): string source

Generates a string of random letters.

Params:

NameTypeAttributeDescription
n number

Length of string

Return:

string

Random letters

public next(): number source

Generates next random number in sequence. This method uses the sine function and some to get the next random number.

Return:

number

Random number in range [0, 1]

public nextFloat(s: number, e: number): number source

Generates a random float in the specified range.

Params:

NameTypeAttributeDescription
s number

Start

e number

End

Return:

number

Random float

public nextInt(s: number, e: number): number source

Generates a random integer in the specified range.

Params:

NameTypeAttributeDescription
s number

Start

e number

End which is inclusive

Return:

number

Random integer

public select(items: Array): Object source

Selects a random element in the supplied collection.

Params:

NameTypeAttributeDescription
items Array

Collection

Return:

Object

Random selection