Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Random

import { Random } from "https://git.sr.ht/~ruivieira/deno-experiments/blob/master/randomjs/mod.ts";

A wrapper around an Engine that provides easy-to-use methods for producing values based on known distributions

class Random {
constructor(engine?: Engine);
readonly engine: Engine;
 
public bool(): boolean;
public bool(percentage: number): boolean;
public bool(numerator: number, denominator: number): boolean;
public bool(numerator?: number, denominator?: number): boolean;
public date(start: Date, end: Date): Date;
public dice(sideCount: number, dieCount: number): number[];
public die(sideCount: number): number;
public hex(length: number, uppercase?: boolean): string;
public int32(): number;
public int53(): number;
public int53Full(): number;
public integer(min: number, max: number): number;
public pick<T>(
source: ArrayLike<T>,
begin?: number,
end?: number,
): T;
public real(
min: number,
max: number,
inclusive?: boolean,
): number;
public realZeroToOneExclusive(): number;
public realZeroToOneInclusive(): number;
public sample<T>(population: ArrayLike<T>, sampleSize: number): T[];
public shuffle<T>(array: T[]): T[];
public string(length: number): string;
public string(length: number, pool: string): string;
public string(length: number, pool?: string): string;
public uint32(): number;
public uint53(): number;
public uint53Full(): number;
public uuid4(): string;
}

§Constructors

§
new Random(engine?: Engine)
[src]

Creates a new Random wrapper

@param engine

The engine to use (defaults to a Math.random-based implementation)

§Properties

§Methods

§
bool(): boolean
[src]

Returns a boolean with 50% probability of being true or false

bool(percentage: number): boolean
[src]

Returns a boolean with the provided percentage of being true

@param percentage

A number within [0, 1] of how often the result should be true

bool(numerator: number, denominator: number): boolean
[src]

Returns a boolean with a probability of numerator/denominator of being true

@param numerator

The numerator of the probability

@param denominator

The denominator of the probability

bool(numerator?: number, denominator?: number): boolean
[src]
§
date(start: Date, end: Date): Date
[src]

Returns a random Date within the inclusive range of [start, end].

@param start

The minimum Date

@param end

The maximum Date

§
dice(sideCount: number, dieCount: number): number[]
[src]

Returns an array of length dieCount of values within [1, sideCount]

@param sideCount

The number of sides of each die

@param dieCount

The number of dice

§
die(sideCount: number): number
[src]

Returns a value within [1, sideCount]

@param sideCount

The number of sides of the die

§
hex(length: number, uppercase?: boolean): string
[src]

Returns a random string comprised of numbers or the characters abcdef (or ABCDEF) of length length.

@param length

Length of the result string

@param uppercase

Whether the string should use ABCDEF instead of abcdef

§
int32(): number
[src]

Returns a value within [-0x80000000, 0x7fffffff]

§
int53(): number
[src]

Returns a value within [-0x20000000000000, 0x1fffffffffffff]

§
int53Full(): number
[src]

Returns a value within [-0x20000000000000, 0x20000000000000]

§
integer(min: number, max: number): number
[src]

Returns a value within [min, max]

@param min

The minimum integer value, inclusive. No less than -0x20000000000000.

@param max

The maximum integer value, inclusive. No greater than 0x20000000000000.

§
pick<T>(source: ArrayLike<T>, begin?: number, end?: number): T
[src]

Return a random value within the provided source within the sliced bounds of begin and end.

@param source

an array of items to pick from

@param begin

the beginning slice index (defaults to 0)

@param end

the ending slice index (defaults to source.length)

§
real(min: number, max: number, inclusive?: boolean): number
[src]

Returns a floating-point value within [min, max) or [min, max]

@param min

The minimum floating-point value, inclusive.

@param max

The maximum floating-point value.

@param inclusive

If true, max will be inclusive.

§
realZeroToOneExclusive(): number
[src]

Returns a floating-point value within [0.0, 1.0)

§
realZeroToOneInclusive(): number
[src]

Returns a floating-point value within [0.0, 1.0]

§
sample<T>(population: ArrayLike<T>, sampleSize: number): T[]
[src]

From the population array, returns an array with sampleSize elements that are randomly chosen without repeats.

@param population

An array that has items to choose a sample from

@param sampleSize

The size of the result array

§
shuffle<T>(array: T[]): T[]
[src]

Shuffles an array in-place

@param array

The array to shuffle

§
string(length: number): string
[src]

Returns a random string using numbers, uppercase and lowercase letters, _, and - of length length.

@param length

Length of the result string

string(length: number, pool: string): string
[src]

Returns a random string using the provided string pool as the possible characters to choose from of length length.

@param length

Length of the result string

string(length: number, pool?: string): string
[src]
§
uint32(): number
[src]

Returns a value within [0, 0xffffffff]

§
uint53(): number
[src]

Returns a value within [0, 0x1fffffffffffff]

§
uint53Full(): number
[src]

Returns a value within [0, 0x20000000000000]

§
uuid4(): string
[src]

Returns a Universally Unique Identifier Version 4.

See http://en.wikipedia.org/wiki/Universally_unique_identifier