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