UNPKG

2.13 kBTypeScriptView Raw
1import type { RandomGenerator } from 'pure-rand';
2/**
3 * Wrapper around an instance of a `pure-rand`'s random number generator
4 * offering a simpler interface to deal with random with impure patterns
5 *
6 * @public
7 */
8export declare class Random {
9 private static MIN_INT;
10 private static MAX_INT;
11 private static DBL_FACTOR;
12 private static DBL_DIVISOR;
13 /**
14 * Create a mutable random number generator by cloning the passed one and mutate it
15 * @param sourceRng - Immutable random generator from pure-rand library, will not be altered (a clone will be)
16 */
17 constructor(sourceRng: RandomGenerator);
18 /**
19 * Clone the random number generator
20 */
21 clone(): Random;
22 /**
23 * Generate an integer having `bits` random bits
24 * @param bits - Number of bits to generate
25 */
26 next(bits: number): number;
27 /**
28 * Generate a random boolean
29 */
30 nextBoolean(): boolean;
31 /**
32 * Generate a random integer (32 bits)
33 */
34 nextInt(): number;
35 /**
36 * Generate a random integer between min (included) and max (included)
37 * @param min - Minimal integer value
38 * @param max - Maximal integer value
39 */
40 nextInt(min: number, max: number): number;
41 /**
42 * Generate a random bigint between min (included) and max (included)
43 * @param min - Minimal bigint value
44 * @param max - Maximal bigint value
45 */
46 nextBigInt(min: bigint, max: bigint): bigint;
47 /**
48 * Generate a random ArrayInt between min (included) and max (included)
49 * @param min - Minimal ArrayInt value
50 * @param max - Maximal ArrayInt value
51 */
52 nextArrayInt(min: {
53 sign: 1 | -1;
54 data: number[];
55 }, max: {
56 sign: 1 | -1;
57 data: number[];
58 }): {
59 sign: 1 | -1;
60 data: number[];
61 };
62 /**
63 * Generate a random floating point number between 0.0 (included) and 1.0 (excluded)
64 */
65 nextDouble(): number;
66 /**
67 * Extract the internal state of the internal RandomGenerator backing the current instance of Random
68 */
69 getState(): readonly number[] | undefined;
70}