repl.txt (3946B)
1 2 {{alias}}() 3 Returns a pseudorandom number drawn from a uniform distribution. 4 5 The default underlying pseudorandom number generator (PRNG) *may* change in 6 the future. If exact reproducibility is required, either use the `factory` 7 method to explicitly specify a PRNG via the `name` option or use an 8 underlying PRNG directly. 9 10 Returns 11 ------- 12 r: number 13 Pseudorandom number on the interval `[0,1)`. 14 15 Examples 16 -------- 17 > var r = {{alias}}(); 18 19 20 {{alias}}.factory( [options] ) 21 Returns a pseudorandom number generator (PRNG) for generating pseudorandom 22 numbers drawn from a uniform distribution. 23 24 Parameters 25 ---------- 26 options: Object (optional) 27 Options. 28 29 options.name: string (optional) 30 Name of the underlying pseudorandom number generator (PRNG). The 31 following PRNGs are supported: 32 33 - mt19937: 32-bit Mersenne Twister. 34 - minstd: linear congruential PRNG based on Park and Miller. 35 - minstd-shuffle: linear congruential PRNG whose output is shuffled. 36 37 Default: 'mt19937'. 38 39 options.seed: any (optional) 40 Pseudorandom number generator seed. Valid seed values vary according to 41 the underlying PRNG. 42 43 options.state: any (optional) 44 Pseudorandom number generator state. Valid state values vary according 45 to the underlying PRNG. If provided, the `seed` option is ignored. 46 47 options.copy: boolean (optional) 48 Boolean indicating whether to copy a provided pseudorandom number 49 generator state. Setting this option to `false` allows sharing state 50 between two or more pseudorandom number generators. Setting this option 51 to `true` ensures that a returned generator has exclusive control over 52 its internal state. Default: true. 53 54 Returns 55 ------- 56 rand: Function 57 Pseudorandom number generator (PRNG). 58 59 Examples 60 -------- 61 // Basic usage: 62 > var rand = {{alias}}.factory(); 63 > var r = rand(); 64 > r = rand(); 65 66 // Specify alternative PRNG: 67 > var rand = {{alias}}.factory({ 'name': 'minstd' }); 68 > r = rand(); 69 > r = rand(); 70 71 72 {{alias}}.NAME 73 Generator name. 74 75 Examples 76 -------- 77 > var str = {{alias}}.NAME 78 'randu' 79 80 81 {{alias}}.PRNG 82 Underlying pseudorandom number generator. 83 84 Examples 85 -------- 86 > var prng = {{alias}}.PRNG; 87 88 89 {{alias}}.MIN 90 Minimum possible value (specific to underlying PRNG). 91 92 Examples 93 -------- 94 > var v = {{alias}}.MIN; 95 96 97 {{alias}}.MAX 98 Maximum possible value (specific to underlying PRNG). 99 100 Examples 101 -------- 102 > var v = {{alias}}.MAX; 103 104 105 {{alias}}.seed 106 Pseudorandom number generator seed. 107 108 Examples 109 -------- 110 > var seed = {{alias}}.seed; 111 112 113 {{alias}}.seedLength 114 Length of generator seed. 115 116 Examples 117 -------- 118 > var len = {{alias}}.seedLength; 119 120 121 {{alias}}.state 122 Generator state. 123 124 Examples 125 -------- 126 > var r = {{alias}}() 127 <number> 128 > r = {{alias}}() 129 <number> 130 > r = {{alias}}() 131 <number> 132 133 // Get a copy of the current state: 134 > var state = {{alias}}.state; 135 136 > r = {{alias}}() 137 <number> 138 > r = {{alias}}() 139 <number> 140 141 // Set the state: 142 > {{alias}}.state = state; 143 144 // Replay the last two pseudorandom numbers: 145 > r = {{alias}}() 146 <number> 147 > r = {{alias}}() 148 <number> 149 150 151 {{alias}}.stateLength 152 Length of generator state. 153 154 Examples 155 -------- 156 > var len = {{alias}}.stateLength; 157 158 159 {{alias}}.byteLength 160 Size (in bytes) of generator state. 161 162 Examples 163 -------- 164 > var sz = {{alias}}.byteLength; 165 166 167 {{alias}}.toJSON() 168 Serializes the pseudorandom number generator as a JSON object. 169 170 Returns 171 ------- 172 out: Object 173 JSON representation. 174 175 Examples 176 -------- 177 > var o = {{alias}}.toJSON() 178 { 'type': 'PRNG', 'name': '...', 'state': {...}, 'params': [] } 179 180 See Also 181 -------- 182