toosoon-utils
Version:
Utility functions & classes
96 lines (95 loc) • 3.22 kB
TypeScript
import type { Point2, Point3 } from './types';
/**
* Generate a random boolean (true or false)
*
* @param {number} [probability=0.5] Probability to get true
* @returns {boolean} Either true or false
*/
export declare function randomBoolean(probability?: number): boolean;
/**
* Generate a random sign (1 or -1)
*
* @param {number} [probability=0.5] Probability to get 1
* @returns {number} Either 1 or -1
*/
export declare function randomSign(probability?: number): number;
/**
* Generate a random floating-point number within a specified range
*
* @param {number} [min=0] Minimum boundary
* @param {number} [max=1] Maximum boundary
* @param {number} [precision=2] Number of digits after the decimal point
* @returns {number} Generated float
*/
export declare function randomFloat(min?: number, max?: number, precision?: number): number;
/**
* Generate a random integer number within a specified range
*
* @param {number} min Minimum boundary
* @param {number} max Maximum boundary
* @returns {number} Generated integer
*/
export declare function randomInt(min: number, max: number): number;
/**
* Generate a random hexadecimal color
*
* @returns {string} Generated hexadecimal color
*/
export declare function randomHexColor(): string;
/**
* Pick a random item from a given array
*
* @param {unknown[]} array Array to pick the item from
* @returns {unknown|undefined} Random item picked
*/
export declare function randomItem<T = unknown>(array: T[]): T | undefined;
/**
* Pick a random property value from a given object
*
* @param {object} object Object to pick the property from
* @returns {unknown|undefined} Random item picked
*/
export declare function randomObjectProperty<T = unknown>(object: Record<string, T>): T | undefined;
/**
* Select a random index from an array of weighted items
*
* @param {number[]} weights Array of weights
* @returns {number} Random index based on weights
*/
export declare function randomIndex(weights: number[]): number;
/**
* Generate a random number fitting a Gaussian (normal) distribution
*
* @param {number} [mean=0] Central value
* @param {number} [spread=1] Standard deviation
* @returns {number} Generated number
*/
export declare function randomGaussian(mean?: number, spread?: number): number;
/**
* Produce a random 2D point around the perimiter of a circle
*
* @param {number} [radius=1] Radius of the circle
* @returns {Point} Random 2D point on the circle
*/
export declare function onCircle(radius?: number): Point2;
/**
* Produce a random 2D point inside a circle
*
* @param {number} [radius=1] Radius of the circle
* @returns {Point} Random 2D point inside the circle
*/
export declare function insideCircle(radius?: number): Point2;
/**
* Produce a random 3D point on the surface of a sphere
*
* @param {number} [radius=1] Radius of the sphere
* @returns {Point3} Random 3D point on the sphere
*/
export declare function onSphere(radius?: number): Point3;
/**
* Produce a random 3D point inside a unit sphere
*
* @param {number} [radius=1] Radius of the sphere
* @returns {Point3} Random 3D point inside the sphere
*/
export declare function insideSphere(radius?: number): Point3;