# .css-1ydg16i{color:#000;-webkit-text-decoration:none;text-decoration:none;}UNPKG

 1 ```// Type definitions for D3JS d3-random module 3.0 ``` 2 ```// Project: https://github.com/d3/d3-random/, https://d3js.org/d3-random ``` 3 ```// Definitions by: Tom Wanzek ``` 4 ```// Alex Ford ``` 5 ```// Boris Yankov ``` 6 ```// Nathan Bierema ``` 7 ```// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped ``` 8 ``` ``` 9 ```// Last module patch version validated against: 3.0.1 ``` 10 ``` ``` 11 ```export interface RandomNumberGenerationSource { ``` 12 ``` /** ``` 13 ``` * Returns the same type of function for generating random numbers but where the given random number ``` 14 ``` * generator source is used as the source of randomness instead of Math.random. ``` 15 ``` * This is useful when a seeded random number generator is preferable to Math.random. ``` 16 ``` * ``` 17 ``` * @param source Source (pseudo-)random number generator implementing the Math.random interface. ``` 18 ``` * The given random number generator must implement the same interface as Math.random and ``` 19 ``` * only return values in the range [0, 1). ``` 20 ``` */ ``` 21 ``` source(source: () => number): this; ``` 22 ```} ``` 23 ``` ``` 24 ```/** ``` 25 ``` * A configurable random number generator for the uniform distribution. ``` 26 ``` */ ``` 27 ```export interface RandomUniform extends RandomNumberGenerationSource { ``` 28 ``` /** ``` 29 ``` * Returns a function for generating random numbers with a uniform distribution. ``` 30 ``` * The minimum allowed value of a returned number is min (inclusive), and the maximum is max (exclusive). ``` 31 ``` * Min defaults to 0; if max is not specified, it defaults to 1. ``` 32 ``` * ``` 33 ``` * @param max The maximum allowed value of a returned number, defaults to 1. ``` 34 ``` */ ``` 35 ``` (max?: number): () => number; ``` 36 ``` /** ``` 37 ``` * Returns a function for generating random numbers with a uniform distribution. ``` 38 ``` * The minimum allowed value of a returned number is min (inclusive), and the maximum is max (exclusive). ``` 39 ``` * ``` 40 ``` * @param min The minimum allowed value of a returned number. ``` 41 ``` * @param max The maximum allowed value of a returned number. ``` 42 ``` */ ``` 43 ``` // tslint:disable-next-line:unified-signatures ``` 44 ``` (min: number, max: number): () => number; ``` 45 ```} ``` 46 ``` ``` 47 ```export const randomUniform: RandomUniform; ``` 48 ``` ``` 49 ```/** ``` 50 ``` * A configurable random integer generator for the uniform distribution. ``` 51 ``` */ ``` 52 ```export interface RandomInt extends RandomNumberGenerationSource { ``` 53 ``` /** ``` 54 ``` * Returns a function for generating random integers with a uniform distribution. ``` 55 ``` * The minimum allowed value of a returned number is ⌊min⌋ (inclusive), and the maximum is ⌊max - 1⌋ (inclusive) ``` 56 ``` * Min defaults to 0. ``` 57 ``` * ``` 58 ``` * @param max The maximum allowed value of a returned number. ``` 59 ``` */ ``` 60 ``` (max: number): () => number; ``` 61 ``` /** ``` 62 ``` * Returns a function for generating random integers with a uniform distribution. ``` 63 ``` * The minimum allowed value of a returned number is ⌊min⌋ (inclusive), and the maximum is ⌊max - 1⌋ (inclusive) ``` 64 ``` * ``` 65 ``` * @param min The minimum allowed value of a returned number. ``` 66 ``` * @param max The maximum allowed value of a returned number. ``` 67 ``` */ ``` 68 ``` // tslint:disable-next-line:unified-signatures ``` 69 ``` (min: number, max: number): () => number; ``` 70 ```} ``` 71 ``` ``` 72 ```export const randomInt: RandomInt; ``` 73 ``` ``` 74 ```/** ``` 75 ``` * A configurable random number generator for the normal (Gaussian) distribution. ``` 76 ``` */ ``` 77 ```export interface RandomNormal extends RandomNumberGenerationSource { ``` 78 ``` /** ``` 79 ``` * Returns a function for generating random numbers with a normal (Gaussian) distribution. ``` 80 ``` * The expected value of the generated numbers is mu, with the given standard deviation sigma. ``` 81 ``` * If mu is not specified, it defaults to 0; if sigma is not specified, it defaults to 1. ``` 82 ``` * ``` 83 ``` * @param mu Expected value, defaults to 0. ``` 84 ``` * @param sigma Standard deviation, defaults to 1. ``` 85 ``` */ ``` 86 ``` (mu?: number, sigma?: number): () => number; ``` 87 ```} ``` 88 ``` ``` 89 ```export const randomNormal: RandomNormal; ``` 90 ``` ``` 91 ```/** ``` 92 ``` * A configurable random number generator for the log-normal distribution. ``` 93 ``` */ ``` 94 ```export interface RandomLogNormal extends RandomNumberGenerationSource { ``` 95 ``` /** ``` 96 ``` * Returns a function for generating random numbers with a log-normal distribution. The expected value of the random variable’s natural logarithm is mu, ``` 97 ``` * with the given standard deviation sigma. If mu is not specified, it defaults to 0; if sigma is not specified, it defaults to 1. ``` 98 ``` * ``` 99 ``` * @param mu Expected value, defaults to 0. ``` 100 ``` * @param sigma Standard deviation, defaults to 1. ``` 101 ``` */ ``` 102 ``` (mu?: number, sigma?: number): () => number; ``` 103 ```} ``` 104 ``` ``` 105 ```export const randomLogNormal: RandomLogNormal; ``` 106 ``` ``` 107 ```/** ``` 108 ``` * A configurable random number generator for the Bates distribution. ``` 109 ``` */ ``` 110 ```export interface RandomBates extends RandomNumberGenerationSource { ``` 111 ``` /** ``` 112 ``` * Returns a function for generating random numbers with a Bates distribution with n independent variables. ``` 113 ``` * The case of fractional n is handled as with d3.randomIrwinHall, and d3.randomBates(0) is equivalent to d3.randomUniform(). ``` 114 ``` * ``` 115 ``` * @param n Number of independent random variables to use. ``` 116 ``` */ ``` 117 ``` (n: number): () => number; ``` 118 ```} ``` 119 ``` ``` 120 ```export const randomBates: RandomBates; ``` 121 ``` ``` 122 ```/** ``` 123 ``` * A configurable random number generator for the Irwin–Hall distribution. ``` 124 ``` */ ``` 125 ```export interface RandomIrwinHall extends RandomNumberGenerationSource { ``` 126 ``` /** ``` 127 ``` * Returns a function for generating random numbers with an Irwin–Hall distribution with n independent variables. ``` 128 ``` * If the fractional part of n is non-zero, this is treated as adding d3.randomUniform() times that fractional part to the integral part. ``` 129 ``` * ``` 130 ``` * @param n Number of independent random variables to use. ``` 131 ``` */ ``` 132 ``` (n: number): () => number; ``` 133 ```} ``` 134 ``` ``` 135 ```export const randomIrwinHall: RandomIrwinHall; ``` 136 ``` ``` 137 ```/** ``` 138 ``` * A configurable random number generator for the exponential distribution. ``` 139 ``` */ ``` 140 ```export interface RandomExponential extends RandomNumberGenerationSource { ``` 141 ``` /** ``` 142 ``` * Returns a function for generating random numbers with an exponential distribution with the rate lambda; ``` 143 ``` * equivalent to time between events in a Poisson process with a mean of 1 / lambda. ``` 144 ``` * ``` 145 ``` * @param lambda Expected time between events. ``` 146 ``` */ ``` 147 ``` (lambda: number): () => number; ``` 148 ```} ``` 149 ``` ``` 150 ```export const randomExponential: RandomExponential; ``` 151 ``` ``` 152 ```/** ``` 153 ``` * A configurable random number generator with an Pareto distribution. ``` 154 ``` */ ``` 155 ```export interface RandomPareto extends RandomNumberGenerationSource { ``` 156 ``` /** ``` 157 ``` * Returns a function for generating random numbers with a Pareto distribution with the shape alpha. ``` 158 ``` * The value alpha must be a positive value. ``` 159 ``` * ``` 160 ``` * @param alpha alpha ``` 161 ``` */ ``` 162 ``` (alpha: number): () => number; ``` 163 ```} ``` 164 ``` ``` 165 ```export const randomPareto: RandomPareto; ``` 166 ``` ``` 167 ```/** ``` 168 ``` * A configurable random 0 or 1 generator according to a Bernoulli distribution. ``` 169 ``` */ ``` 170 ```export interface RandomBernoulli extends RandomNumberGenerationSource { ``` 171 ``` /** ``` 172 ``` * Returns a function for generating either 1 or 0 according to a Bernoulli distribution with 1 being returned with success probability p and 0 with failure probability q = 1 - p. ``` 173 ``` * The value p is in the range [0, 1]. ``` 174 ``` * ``` 175 ``` * @param p p ``` 176 ``` */ ``` 177 ``` (p: number): () => number; ``` 178 ```} ``` 179 ``` ``` 180 ```export const randomBernoulli: RandomBernoulli; ``` 181 ``` ``` 182 ```/** ``` 183 ``` * A configurable random number generator with a geometric distribution. ``` 184 ``` */ ``` 185 ```export interface RandomGeometric extends RandomNumberGenerationSource { ``` 186 ``` /** ``` 187 ``` * Returns a function for generating numbers with a geometric distribution with success probability p. ``` 188 ``` * The value p is in the range [0, 1]. ``` 189 ``` * ``` 190 ``` * @param p Success probability ``` 191 ``` */ ``` 192 ``` (p: number): () => number; ``` 193 ```} ``` 194 ``` ``` 195 ```export const randomGeometric: RandomGeometric; ``` 196 ``` ``` 197 ```/** ``` 198 ``` * A configurable random number generator with a binomial distribution. ``` 199 ``` */ ``` 200 ```export interface RandomBinomial extends RandomNumberGenerationSource { ``` 201 ``` /** ``` 202 ``` * Returns a function for generating numbers with a geometric distribution with success probability p. ``` 203 ``` * The value p is in the range (0, 1]. ``` 204 ``` * ``` 205 ``` * @param p Success probability ``` 206 ``` */ ``` 207 ``` (p: number): () => number; ``` 208 ```} ``` 209 ``` ``` 210 ```export const randomBinomial: RandomBinomial; ``` 211 ``` ``` 212 ```/** ``` 213 ``` * A configurable random number generator with a gamma distribution. ``` 214 ``` */ ``` 215 ```export interface RandomGamma extends RandomNumberGenerationSource { ``` 216 ``` /** ``` 217 ``` * Returns a function for generating random numbers with a gamma distribution with k the shape parameter and theta the scale parameter. ``` 218 ``` * The value k must be a positive value; if theta is not specified, it defaults to 1. ``` 219 ``` * ``` 220 ``` * @param k Shape parameter ``` 221 ``` * @param theta Scale paramter ``` 222 ``` */ ``` 223 ``` (k: number, theta?: number): () => number; ``` 224 ```} ``` 225 ``` ``` 226 ```export const randomGamma: RandomGamma; ``` 227 ``` ``` 228 ```/** ``` 229 ``` * A configurable random number generator with a beta distribution. ``` 230 ``` */ ``` 231 ```export interface RandomBeta extends RandomNumberGenerationSource { ``` 232 ``` /** ``` 233 ``` * Returns a function for generating random numbers with a beta distribution with alpha and beta shape parameters, which must both be positive. ``` 234 ``` * ``` 235 ``` * @param alpha Shape parameter ``` 236 ``` * @param beta Shape paramter ``` 237 ``` */ ``` 238 ``` (alpha: number, beta: number): () => number; ``` 239 ```} ``` 240 ``` ``` 241 ```export const randomBeta: RandomBeta; ``` 242 ``` ``` 243 ```/** ``` 244 ``` * A configurable random number generator with one of the generalized extreme value distributions. ``` 245 ``` */ ``` 246 ```export interface RandomWeibull extends RandomNumberGenerationSource { ``` 247 ``` /** ``` 248 ``` * Returns a function for generating random numbers with one of the generalized extreme value distributions, depending on k: ``` 249 ``` * If k is positive, the Weibull distribution with shape parameter k ``` 250 ``` * If k is zero, the Gumbel distribution ``` 251 ``` * If k is negative, the Fréchet distribution with shape parameter −k ``` 252 ``` * In all three cases, a is the location parameter and b is the scale parameter. ``` 253 ``` * If a is not specified, it defaults to 0; if b is not specified, it defaults to 1. ``` 254 ``` * ``` 255 ``` * @param k Shape parameter ``` 256 ``` * @param a Location parameter ``` 257 ``` * @param b Scale parameter ``` 258 ``` */ ``` 259 ``` (k: number, a?: number, b?: number): () => number; ``` 260 ```} ``` 261 ``` ``` 262 ```export const randomWeibull: RandomWeibull; ``` 263 ``` ``` 264 ```/** ``` 265 ``` * A configurable random number generator with a Cauchy distribution. ``` 266 ``` */ ``` 267 ```export interface RandomCauchy extends RandomNumberGenerationSource { ``` 268 ``` /** ``` 269 ``` * Returns a function for generating random numbers with a Cauchy distribution. ``` 270 ``` * a and b have the same meanings and default values as in d3.randomWeibull. ``` 271 ``` * ``` 272 ``` * @param a Location parameter ``` 273 ``` * @param b Scale parameter ``` 274 ``` */ ``` 275 ``` (a?: number, b?: number): () => number; ``` 276 ```} ``` 277 ``` ``` 278 ```export const randomCauchy: RandomCauchy; ``` 279 ``` ``` 280 ```/** ``` 281 ``` * A configurable random number generator with a logistic distribution. ``` 282 ``` */ ``` 283 ```export interface RandomLogistic extends RandomNumberGenerationSource { ``` 284 ``` /** ``` 285 ``` * Returns a function for generating random numbers with a logistic distribution. ``` 286 ``` * a and b have the same meanings and default values as in d3.randomWeibull. ``` 287 ``` * ``` 288 ``` * @param a Location parameter ``` 289 ``` * @param b Scale parameter ``` 290 ``` */ ``` 291 ``` (a?: number, b?: number): () => number; ``` 292 ```} ``` 293 ``` ``` 294 ```export const randomLogistic: RandomLogistic; ``` 295 ``` ``` 296 ```/** ``` 297 ``` * A configurable random number generator with a Poisson distribution. ``` 298 ``` */ ``` 299 ```export interface RandomPoisson extends RandomNumberGenerationSource { ``` 300 ``` /** ``` 301 ``` * Returns a function for generating random numbers with a Poisson distribution with mean lambda. ``` 302 ``` * ``` 303 ``` * @param lambda Mean ``` 304 ``` */ ``` 305 ``` (lambda: number): () => number; ``` 306 ```} ``` 307 ``` ``` 308 ```export const randomPoisson: RandomPoisson; ``` 309 ``` ``` 310 ```/** ``` 311 ``` * Returns a linear congruential generator; ``` 312 ``` * this function can be called repeatedly to obtain pseudorandom values well-distributed on the interval [0,1) and with a long period (up to 1 billion numbers), similar to Math.random. ``` 313 ``` * A seed can be specified as a real number in the interval [0,1) or as any integer. ``` 314 ``` * In the latter case, only the lower 32 bits are considered. ``` 315 ``` * Two generators instanced with the same seed generate the same sequence, allowing to create reproducible pseudo-random experiments. ``` 316 ``` * If the seed is not specified, one is chosen using Math.random. ``` 317 ``` * ``` 318 ``` * @param seed A seed that is either a real number in the interval [0,1) or any integer. ``` 319 ``` */ ``` 320 ```export function randomLcg(seed?: number): () => number; ```