Skip to main content
The Deno 2 Release Candidate is here
Learn more
class RandomUtil
import { RandomUtil } from "https://deno.land/x/sptaki@1.2.0/utils/RandomUtil.d.ts";

Constructors

new
RandomUtil(jsonUtil: JsonUtil, logger: ILogger)

Properties

protected
jsonUtil: JsonUtil
protected
logger: ILogger

Methods

drawRandomFromDict(
dict: any,
count?: number,
replacement?: boolean,
): any[]

Draw a random (top level) element of the provided dictionary N times to return an array of N random dictionary keys Drawing can be with or without replacement

drawRandomFromList<T>(
originalList: Array<T>,
count?: number,
replacement?: boolean,
): Array<T>

Draw a random element of the provided list N times to return an array of N random elements Drawing can be with or without replacement

getArrayValue<T>(arr: T[]): T
getBiasedRandomNumber(
min: number,
max: number,
shift: number,
n: number,
): number
getBool(): boolean
getChance100(chancePercent: number): boolean

Check if number passes a check out of 100

getFloat(min: number, max: number): number
getInt(min: number, max: number): number
getIntEx(max: number): number
getKey(node: any): string
getKeyValue(node: { [x: string]: any; }): any
getNormallyDistributedRandomNumber(
mean: number,
sigma: number,
attempt?: number,
): number

Generate a normally distributed random number Uses the Box-Muller transform

getPercentOfValue(
percent: number,
number: number,
toFixed?: number,
): number
getStringArrayValue(arr: string[]): string
randInt(low: number, high?: number): number

Draw Random integer low inclusive, high exclusive if high is not set we draw from 0 to low (exclusive)

reduceValueByPercent(number: number, percentage: number): number

Reduce a value by a percentage

rollForChanceProbability(probabilityChance: number): boolean

Rolls for a probability based on chance

shuffle<T>(array: Array<T>): Array<T>

Fisher-Yates shuffle an array