UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

25 lines (24 loc) 956 B
/** * Returns true at rate of the percentLikelyToBeTrue input. Inputs should be whole numbers which * will be treated like percents. Anything outside of 0-100 inclusively will be clamped. An input 0 * will always return true. An input of 100 will always return true. Decimals on the input will be * chopped off, use whole numbers. * * This function uses cryptographically secure randomness. * * @category Random * @category Package : @augment-vir/common * @example * * ```ts * import {randomBoolean} from '@augment-vir/common'; * * randomBoolean(50); // 50% chance to return true * randomBoolean(0); // always false, 0% chance of being true * randomBoolean(100); // always true, 100% chance of being true * randomBoolean(59.67); // 59% chance of being true * ``` * * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function randomBoolean(percentLikelyToBeTrue?: number): boolean;