repl.txt (4297B)
1 2 {{alias}}( a, b ) 3 Returns a pseudorandom number drawn from a discrete uniform distribution. 4 5 If `a > b`, the function returns `NaN`. 6 7 If `a` or `b` is not an integer value, the function returns `NaN`. 8 9 Parameters 10 ---------- 11 a: integer 12 Minimum support. 13 14 b: integer 15 Maximum support. 16 17 Returns 18 ------- 19 r: integer 20 Pseudorandom number. 21 22 Examples 23 -------- 24 > var r = {{alias}}( 2, 50 ); 25 26 27 {{alias}}.factory( [a, b, ][options] ) 28 Returns a pseudorandom number generator (PRNG) for generating pseudorandom 29 numbers drawn from a discrete uniform distribution. 30 31 If provided `a` and `b`, the returned PRNG returns random variates drawn 32 from the specified distribution. 33 34 If not provided `a` and `b`, the returned PRNG requires that both `a` and 35 `b` be provided at each invocation. 36 37 Parameters 38 ---------- 39 a: integer (optional) 40 Minimum support. 41 42 b: integer (optional) 43 Maximum support. 44 45 options: Object (optional) 46 Options. 47 48 options.prng: Function (optional) 49 Pseudorandom number generator (PRNG) for generating uniformly 50 distributed pseudorandom integers. If provided, the `state` and `seed` 51 options are ignored. In order to seed the returned pseudorandom number 52 generator, one must seed the provided `prng` (assuming the provided 53 `prng` is seedable). The provided PRNG must have `MIN` and `MAX` 54 properties specifying the minimum and maximum possible pseudorandom 55 integers. 56 57 options.seed: integer|ArrayLikeObject<integer> (optional) 58 Pseudorandom number generator seed. The seed may be either a positive 59 unsigned 32-bit integer or, for arbitrary length seeds, an array-like 60 object containing unsigned 32-bit integers. 61 62 options.state: Uint32Array (optional) 63 Pseudorandom number generator state. If provided, the `seed` option is 64 ignored. 65 66 options.copy: boolean (optional) 67 Boolean indicating whether to copy a provided pseudorandom number 68 generator state. Setting this option to `false` allows sharing state 69 between two or more pseudorandom number generators. Setting this option 70 to `true` ensures that a returned generator has exclusive control over 71 its internal state. Default: true. 72 73 Returns 74 ------- 75 rand: Function 76 Pseudorandom number generator (PRNG). 77 78 Examples 79 -------- 80 // Basic usage: 81 > var rand = {{alias}}.factory(); 82 > var r = rand( 0, 10 ); 83 > r = rand( -20, 20 ); 84 85 // Provide `a` and `b`: 86 > rand = {{alias}}.factory( 0, 10 ); 87 > r = rand(); 88 > r = rand(); 89 90 91 {{alias}}.NAME 92 Generator name. 93 94 Examples 95 -------- 96 > var str = {{alias}}.NAME 97 'discrete-uniform' 98 99 100 {{alias}}.PRNG 101 Underlying pseudorandom number generator. 102 103 Examples 104 -------- 105 > var prng = {{alias}}.PRNG; 106 107 108 {{alias}}.seed 109 Pseudorandom number generator seed. 110 111 Examples 112 -------- 113 > var seed = {{alias}}.seed; 114 115 116 {{alias}}.seedLength 117 Length of generator seed. 118 119 Examples 120 -------- 121 > var len = {{alias}}.seedLength; 122 123 124 {{alias}}.state 125 Generator state. 126 127 Examples 128 -------- 129 > var r = {{alias}}( 2, 50 ) 130 <number> 131 > r = {{alias}}( 2, 50 ) 132 <number> 133 > r = {{alias}}( 2, 50 ) 134 <number> 135 136 // Get a copy of the current state: 137 > var state = {{alias}}.state 138 <Uint32Array> 139 140 > r = {{alias}}( 2, 50 ) 141 <number> 142 > r = {{alias}}( 2, 50 ) 143 <number> 144 145 // Set the state: 146 > {{alias}}.state = state; 147 148 // Replay the last two pseudorandom numbers: 149 > r = {{alias}}( 2, 50 ) 150 <number> 151 > r = {{alias}}( 2, 50 ) 152 <number> 153 154 155 {{alias}}.stateLength 156 Length of generator state. 157 158 Examples 159 -------- 160 > var len = {{alias}}.stateLength; 161 162 163 {{alias}}.byteLength 164 Size (in bytes) of generator state. 165 166 Examples 167 -------- 168 > var sz = {{alias}}.byteLength; 169 170 171 {{alias}}.toJSON() 172 Serializes the pseudorandom number generator as a JSON object. 173 174 Returns 175 ------- 176 out: Object 177 JSON representation. 178 179 Examples 180 -------- 181 > var o = {{alias}}.toJSON() 182 { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } 183 184 See Also 185 -------- 186