|
| 1 | +import { Engine } from "./types"; |
| 2 | +/** |
| 3 | + * A wrapper around an Engine that provides easy-to-use methods for |
| 4 | + * producing values based on known distributions |
| 5 | + */ |
| 6 | +export declare class Random { |
| 7 | + private readonly engine; |
| 8 | + /** |
| 9 | + * Creates a new Random wrapper |
| 10 | + * @param engine The engine to use (defaults to a `Math.random`-based implementation) |
| 11 | + */ |
| 12 | + constructor(); |
| 13 | + /** |
| 14 | + * Creates a new Random wrapper |
| 15 | + * @param engine The engine to use (explicitly provided) |
| 16 | + */ |
| 17 | + constructor(engine: Engine); |
| 18 | + /** |
| 19 | + * Creates a new Random wrapper that automatically detects |
| 20 | + * and uses the best available engine for the current environment. |
| 21 | + * @returns A Random instance using auto-detected engine |
| 22 | + */ |
| 23 | + static auto(): Random; |
| 24 | + /** |
| 25 | + * Returns a value within [-0x80000000, 0x7fffffff] |
| 26 | + */ |
| 27 | + int32(): number; |
| 28 | + /** |
| 29 | + * Returns a value within [0, 0xffffffff] |
| 30 | + */ |
| 31 | + uint32(): number; |
| 32 | + /** |
| 33 | + * Returns a value within [0, 0x1fffffffffffff] |
| 34 | + */ |
| 35 | + uint53(): number; |
| 36 | + /** |
| 37 | + * Returns a value within [0, 0x20000000000000] |
| 38 | + */ |
| 39 | + uint53Full(): number; |
| 40 | + /** |
| 41 | + * Returns a value within [-0x20000000000000, 0x1fffffffffffff] |
| 42 | + */ |
| 43 | + int53(): number; |
| 44 | + /** |
| 45 | + * Returns a value within [-0x20000000000000, 0x20000000000000] |
| 46 | + */ |
| 47 | + int53Full(): number; |
| 48 | + /** |
| 49 | + * Returns a value within [min, max] |
| 50 | + * @param minimum The minimum integer value, inclusive. No less than -0x20000000000000. |
| 51 | + * @param maximum The maximum integer value, inclusive. No greater than 0x20000000000000. |
| 52 | + */ |
| 53 | + integer(minimum: number, maximum: number): number; |
| 54 | + /** |
| 55 | + * Returns the maximum of the values specified within [min, max] |
| 56 | + * @param minimum The minimum integer value, inclusive. No less than -0x20000000000000. Discarded. |
| 57 | + * @param maximum The maximum integer value, inclusive. No greater than 0x20000000000000. |
| 58 | + */ |
| 59 | + max(minimum: number, maximum: number): number; |
| 60 | + /** |
| 61 | + * Returns the minimum of the values specified within [min, max] |
| 62 | + * @param minimum The minimum integer value, inclusive. No less than -0x20000000000000. |
| 63 | + * @param maximum The maximum integer value, inclusive. No greater than 0x20000000000000. Discarded. |
| 64 | + */ |
| 65 | + min(minimum: number, maximum: number): number; |
| 66 | + /** |
| 67 | + * Returns a floating-point value within [0.0, 1.0] |
| 68 | + */ |
| 69 | + realZeroToOneInclusive(): number; |
| 70 | + /** |
| 71 | + * Returns a floating-point value within [0.0, 1.0) |
| 72 | + */ |
| 73 | + realZeroToOneExclusive(): number; |
| 74 | + /** |
| 75 | + * Returns a floating-point value within [min, max) or [min, max] |
| 76 | + * @param min The minimum floating-point value, inclusive. |
| 77 | + * @param max The maximum floating-point value. |
| 78 | + * @param inclusive If true, `max` will be inclusive. |
| 79 | + */ |
| 80 | + real(minimum: number, maximum: number, inclusive?: boolean): number; |
| 81 | + /** |
| 82 | + * Returns a boolean with 50% probability of being true or false |
| 83 | + */ |
| 84 | + bool(): boolean; |
| 85 | + /** |
| 86 | + * Returns a boolean with the provided `percentage` of being true |
| 87 | + * @param percentage A number within [0, 1] of how often the result should be `true` |
| 88 | + */ |
| 89 | + bool(percentage: number): boolean; |
| 90 | + /** |
| 91 | + * Returns a boolean with a probability of `numerator`/`denominator` of being true |
| 92 | + * @param numerator The numerator of the probability |
| 93 | + * @param denominator The denominator of the probability |
| 94 | + */ |
| 95 | + bool(numerator: number, denominator: number): boolean; |
| 96 | + /** |
| 97 | + * Return a random value within the provided `source` within the sliced |
| 98 | + * bounds of `begin` and `end`. |
| 99 | + * @param source an array of items to pick from |
| 100 | + * @param begin the beginning slice index (defaults to `0`) |
| 101 | + * @param end the ending slice index (defaults to `source.length`) |
| 102 | + */ |
| 103 | + pick<T>(source: ArrayLike<T>, begin?: number, end?: number): T; |
| 104 | + /** |
| 105 | + * Shuffles an array in-place |
| 106 | + * @param array The array to shuffle |
| 107 | + */ |
| 108 | + shuffle<T>(array: T[]): T[]; |
| 109 | + /** |
| 110 | + * From the population array, returns an array with sampleSize elements that |
| 111 | + * are randomly chosen without repeats. |
| 112 | + * @param population An array that has items to choose a sample from |
| 113 | + * @param sampleSize The size of the result array |
| 114 | + */ |
| 115 | + sample<T>(population: ArrayLike<T>, sampleSize: number): T[]; |
| 116 | + /** |
| 117 | + * Returns a value within [1, sideCount] |
| 118 | + * @param sideCount The number of sides of the die |
| 119 | + */ |
| 120 | + die(sideCount: number): number; |
| 121 | + /** |
| 122 | + * Returns an array of length `dieCount` of values within [1, sideCount] |
| 123 | + * @param sideCount The number of sides of each die |
| 124 | + * @param dieCount The number of dice |
| 125 | + */ |
| 126 | + dice(sideCount: number, dieCount: number): number[]; |
| 127 | + /** |
| 128 | + * Returns a Universally Unique Identifier Version 4. |
| 129 | + * |
| 130 | + * See https://en.wikipedia.org/wiki/Universally_unique_identifier |
| 131 | + */ |
| 132 | + uuid4(): string; |
| 133 | + /** |
| 134 | + * Returns a random string using numbers, uppercase and lowercase letters, |
| 135 | + * `_`, and `-` of length `length`. |
| 136 | + * @param length Length of the result string |
| 137 | + */ |
| 138 | + string(length: number): string; |
| 139 | + /** |
| 140 | + * Returns a random string using the provided string pool as the possible |
| 141 | + * characters to choose from of length `length`. |
| 142 | + * @param length Length of the result string |
| 143 | + */ |
| 144 | + string(length: number, pool: string): string; |
| 145 | + /** |
| 146 | + * Returns a random string comprised of numbers or the characters `abcdef` |
| 147 | + * (or `ABCDEF`) of length `length`. |
| 148 | + * @param length Length of the result string |
| 149 | + * @param uppercase Whether the string should use `ABCDEF` instead of `abcdef` |
| 150 | + */ |
| 151 | + hex(length: number, uppercase?: boolean): string; |
| 152 | + /** |
| 153 | + * Returns a random `Date` within the inclusive range of [`start`, `end`]. |
| 154 | + * @param start The minimum `Date` |
| 155 | + * @param end The maximum `Date` |
| 156 | + */ |
| 157 | + date(start: Date, end: Date): Date; |
| 158 | +} |
0 commit comments