new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

D3 · all subjects

d3-random

22 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

d3-random module overview

d3-random generates random numbers from various distributions including uniform, normal, log-normal, Bates, Irwin-Hall, exponential, Pareto, Bernoulli, geometric, binomial, gamma, beta, Weibull, Cauchy, logistic, and Poisson, with optional custom random source.

d3-random distribution functions

Random distribution generators: d3.randomUniform (uniform), d3.randomInt (uniform integer), d3.randomNormal (normal), d3.randomLogNormal (log-normal), d3.randomBates (Bates), d3.randomIrwinHall (Irwin-Hall), d3.randomExponential (exponential), d3.randomPareto (Pareto), d3.randomBernoulli (Bernoulli), d3.randomGeometric (geometric), d3.randomBinomial (binomial), d3.randomGamma (gamma), d3.randomBeta (beta), d3.randomWeibull (Weibull/Gumbel/Fréchet), d3.randomCauchy (Cauchy), d3.randomLogistic (logistic), d3.randomPoisson (Poisson).

d3-random configuration

Random generator configuration methods: random.source (set source of randomness). Pseudorandom generator: d3.randomLcg (seeded linear congruential generator).

randomUniform signature and behavior

d3.randomUniform(min, max) returns a function for generating random numbers with a uniform distribution. The minimum allowed value of a returned number is min (inclusive), and the maximum is max (exclusive). If min is not specified, it defaults to 0; if max is not specified, it defaults to 1. Example: d3.randomUniform(6) generates numbers ≥0 and <6.

randomInt signature and behavior

d3.randomInt(min, max) returns a function for generating random integers with a uniform distribution. The minimum allowed value of a returned number is ⌊min⌋ (inclusive), and the maximum is ⌊max - 1⌋ (inclusive). If min is not specified, it defaults to 0. Example: d3.randomInt(100) generates integers ≥0 and <100.

randomNormal signature and defaults

d3.randomNormal(mu, sigma) returns a function for generating random numbers with a normal (Gaussian) distribution. The expected value of the generated numbers is mu, with the given standard deviation sigma. If mu is not specified, it defaults to 0; if sigma is not specified, it defaults to 1.

randomLogNormal signature and defaults

d3.randomLogNormal(mu, sigma) returns a function for generating random numbers with a log-normal distribution. The expected value of the random variable's natural logarithm is mu, with the given standard deviation sigma. If mu is not specified, it defaults to 0; if sigma is not specified, it defaults to 1.

randomBates signature and behavior

d3.randomBates(n) returns a function for generating random numbers with a Bates distribution with n independent variables. The function generates numbers between 0 and 1. Fractional n is handled as with d3.randomIrwinHall, and d3.randomBates(0) is equivalent to d3.randomUniform().

randomIrwinHall signature and behavior

d3.randomIrwinHall(n) returns a function for generating random numbers with an Irwin–Hall distribution with n independent variables. If the fractional part of n is non-zero, this is treated as adding d3.randomUniform() times that fractional part to the integral part. Example: d3.randomIrwinHall(3) generates numbers between 0 and 3.

randomExponential signature and interpretation

d3.randomExponential(lambda) returns a function for generating random numbers with an exponential distribution with the rate lambda. This is equivalent to time between events in a Poisson process with a mean of 1 / lambda. For example, randomExponential(1 / 40) generates random times between events where, on average, one event occurs every 40 units of time.

randomPareto signature and constraints

d3.randomPareto(alpha) returns a function for generating random numbers with a Pareto distribution with the shape alpha. The value alpha must be a positive value.

randomBernoulli signature and behavior

d3.randomBernoulli(p) 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. The value p is in the range [0, 1].

randomGeometric signature and constraints

d3.randomGeometric(p) returns a function for generating numbers with a geometric distribution with success probability p. The value p is in the range [0, 1].

randomBinomial signature and constraints

d3.randomBinomial(n, p) returns a function for generating random numbers with a binomial distribution with n the number of trials and p the probability of success in each trial. The value n is greater than or equal to 0, and the value p is in the range [0, 1].

randomGamma signature and defaults

d3.randomGamma(k, theta) returns a function for generating random numbers with a gamma distribution with k the shape parameter and theta the scale parameter. The value k must be a positive value; if theta is not specified, it defaults to 1.

randomBeta signature and constraints

d3.randomBeta(alpha, beta) returns a function for generating random numbers with a beta distribution with alpha and beta shape parameters, which must both be positive.

randomWeibull signature and distribution selection

d3.randomWeibull(k, a, b) returns a function for generating random numbers with one of the generalized extreme value distributions, depending on k: If k is positive, the Weibull distribution with shape parameter k; If k is zero, the Gumbel distribution; If k is negative, the Fréchet distribution with shape parameter −k. In all three cases, a is the location parameter and b is the scale parameter. If a is not specified, it defaults to 0; if b is not specified, it defaults to 1.

randomCauchy signature and defaults

d3.randomCauchy(a, b) returns a function for generating random numbers with a Cauchy distribution. The parameters a and b have the same meanings and default values as in d3.randomWeibull: a is the location parameter defaulting to 0, and b is the scale parameter defaulting to 1.

randomLogistic signature and defaults

d3.randomLogistic(a, b) returns a function for generating random numbers with a logistic distribution. The parameters a and b have the same meanings and default values as in d3.randomWeibull: a is the location parameter defaulting to 0, and b is the scale parameter defaulting to 1.

randomPoisson signature

d3.randomPoisson(lambda) returns a function for generating random numbers with a Poisson distribution with mean lambda.

random.source method for custom random source

All random distribution functions have a .source(source) method that returns the same type of function for generating random numbers but where the given random number generator source is used as the source of randomness instead of Math.random. The given random number generator must implement the same interface as Math.random and only return values in the range [0, 1). This is useful when a seeded random number generator is preferable to Math.random. Example: const random = d3.randomNormal.source(d3.randomLcg(0.44871573888282423))(0, 1); random(); // -0.6253955998897069

randomLcg signature and behavior

d3.randomLcg(seed) returns a linear congruential generator; 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. A seed can be specified as a real number in the interval [0,1) or as any integer. In the latter case, only the lower 32 bits are considered. Two generators instanced with the same seed generate the same sequence, allowing to create reproducible pseudo-random experiments. If the seed is not specified, one is chosen using Math.random.

Give your agent this brain