Wiki ▸ [[API Reference]] ▸ [[Core]] ▸ Math

## Pseudorandom Number Generation

You can use the built-in Math.random to generate uniform distributions. For example, to generate a random integer between 0 and 99 (inclusive), you can say `Math.floor(Math.random() * 100)`.

# d3.random.normal([mean, [deviation]])

Returns a function for generating random numbers with a normal (Gaussian) distribution. The expected value of the generated pseudorandom numbers is mean, with the given standard deviation. If deviation is not specified, it defaults to 1.0; if mean is not specified, it defaults to 0.0.

# d3.random.logNormal([mean, [deviation]])

Returns a function for generating random numbers with a log-normal distribution. The expected value of the random variable’s natural logrithm is mean, with the given standard deviation. If deviation is not specified, it defaults to 1.0; if mean is not specified, it defaults to 0.0.

# d3.random.bates(count)

Returns a function for generating random numbers with a Bates distribution. The number of independent variables is specified by count.

# d3.random.irwinHall(count)

Returns a function for generating random numbers with an Irwin–Hall distribution. The number of independent variables is specified by count.

## 2D Transforms

# d3.transform(string)

Parses the given 2D affine transform string, as defined by SVG's transform attribute. The transform is then decomposed to an object with fields for translate, rotate, x-skew and scale. This behavior is standardized by CSS: see matrix decomposition for animation.

# transform.rotate

Returns the rotation angle θ of this transform, in degrees.

# transform.translate

Returns the [dx, dy] translation of this transform, as a two-element array in local coordinates (typically pixels).

# transform.skew

Returns the x-skew φ of this transform, in degrees.

# transform.scale

Returns the [kx, ky] scale of this transform, as a two-element array.

# transform.toString()

Returns a string representation of this transform, in the form "translate(dx,dy)rotate(θ)skewX(φ)scale(kx,ky)".