What is this?

is a general purpose random generator library, primarily aimed at testing. Beyond providing numbers following specific distributions, can be used to generate different random objects, such as CSS or SVG attributes and elements.

How can I use it?

Browser

Just include the minified js source in the header:
<script type="text/javascript" src="dice.min.js"></script>

Node

TODO

API

core

Core functionality, implements basic uniform generators and array manipulators.

float

dice.core.float([min[, max[, n]]])

Generates some uniformly distributed random floats in (min, max). If min > max, a random float in (max, min) is generated. If no parameters are passed, generates a single random float between 0 and 1. If only min is specified, generates a single random float between 0 and min.
argumentdescription
minLower boundary, or upper if max is not given.
maxUpper boundary.
nNumber of floats to generate.
returnsdescription
number, ArraySingle float or array of random floats.

int

dice.core.int(min[, max[, n]])

Generates some uniformly distributed random integers in (min, max). If min > max, a random integer in (max, min) is generated. If only min is specified, generates a single random integer between 0 and min.
argumentdescription
minLower boundary, or upper if max is not specified.
maxUpper boundary.
nNumber of integers to generate.
returnsdescription
number, ArraySingle integer or array of random integers.

choice

dice.core.choice(values[, n])

Samples some elements with replacement from an array with uniform distribution.
argumentdescription
valuesArray to sample from.
nNumber of elements to sample.
returnsdescription
object, ArraySingle element or array of sampled elements. If array is invalid, null pointer is returned.

char

dice.core.char(string[, n])

Samples some characters with replacement from a string with uniform distribution.
argumentdescription
stringString to sample characters from.
nNumber of characters to sample.
returnsdescription
string, ArrayRandom character if k is not given or less than 2, an array of random characters otherwise.

shuffle

dice.core.shuffle(values)

Shuffles an array in-place using the Fisher--Yates algorithm.
argumentdescription
valuesArray to shuffle.

coin

dice.core.coin(p, head, tail[, n])

Flips a biased coin several times and returns the associated head/tail value or array of values.
argumentdescription
pBias (probability of head).
headHead value.
tailTail value.
nNumber of coins to flip.
returnsdescription
object, ArrayObject of head/tail value or an array of head/tail values.

dist

A collection of generators for well-known distributions.

uniform

dice.dist.uniform(min, max[, n])

Generates some uniformly distributed random values.
argumentdescription
minLower boundary.
maxUpper boundary.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

exponential

dice.dist.exponential(lambda[, n])

Generates some exponentially distributed random values.
argumentdescription
lambdaRate parameter.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

pareto

dice.dist.pareto(xmin, alpha[, n])

Generates some Pareto distributed random values.
argumentdescription
xminScale parameter.
alphaShape parameter.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

boundedPareto

dice.dist.boundedPareto(xmin, xmax, alpha[, n])

Generates some bounded Pareto distributed random values.
argumentdescription
xminLower boundary.
xmaxUpper boundary.
alphaShape parameter.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

normal

dice.dist.normal(mu, sigma[, n])

Generates some normally distributed random values.
argumentdescription
muLocation parameter (mean).
sigmaSquared scale parameter (variance).
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

lognormal

dice.dist.lognormal(mu, sigma[, n])

Generates some log-normally distributed random values.
argumentdescription
muLocation parameter.
sigmaScale parameter.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

weibull

dice.dist.weibull(lambda, k[, n])

Generates some Weibull distributed random values.
argumentdescription
lambdaScale parameter.
kShape parameter.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

poisson

dice.dist.poisson(lambda[, n])

Generates some Poisson distributed random values. FIXME use different methods for small/large lambda
argumentdescription
lambdaMean of the distribution.
nNumber of values to return.
returnsdescription
number, ArraySingle value or array of random values.

css

A collection of methods to generate CSS content types.

CSSContent

dice.css.CSSContent

Class describing a random CSS content.
propertydescription
iObject corresponding to the CSS content. Can be a single string, an array, etc.
oString representation of the CSS content. This is the final value that is put after the colon in a property:value pair.

integer

dice.css.integer()

Generates a random CSS integer.
returnsdescription
CSSContentRandom CSS integer.

number

dice.css.number()

Generates a random CSS number.
returnsdescription
CSSContentRandom CSS number.

length

dice.css.length()

Generates a random CSS length.
returnsdescription
CSSContentRandom CSS length.

opacityValue

dice.css.opacityValue()

Generates a random CSS opacity-value.
returnsdescription
CSSContentRandom CSS opacityValue.

color

dice.css.color()

Generates a random CSS color.
returnsdescription
CSSContentRandom CSS color.

svg

Collection of generators for SVG content.

SVGContent

dice.svg.SVGContent

Class describing a random SVG content. This is an alias for CSSContent.
propertydescription
iObject corresponding to the SVG content. Can be a single string, an array, etc.
oString representation of the SVG content. This is the final value that is put after the colon in a property:value pair.

integer

dice.svg.integer()

Generates a random SVG integer.
returnsdescription
SVGContentRandom SVG integer.

number

dice.svg.number()

Generates a random SVG number.
returnsdescription
SVGContentRandom SVG number.

length

dice.svg.length()

Generates a random SVG length.
returnsdescription
SVGContentRandom SVG length.

coordinate

dice.svg.coordinate()

Generates a random SVG coordinate.
returnsdescription
SVGContentRandom SVG coordinate.

color

dice.svg.color()

Generates a random SVG color.
returnsdescription
SVGContentRandom SVG color.

opacityValue

dice.svg.opacityValue()

Generates a random SVG opacity-value.
returnsdescription
SVGContentRandom SVG opacity-value.

transformList

dice.svg.transformList()

Generates a random SVG transform-list.
returnsdescription
SVGContentRandom SVG transform-list.

point

dice.svg.point()

Generates a random point.
returnsdescription
SVGContentRandom SVG point.

path

dice.svg.path()

Generates a random path.
returnsdescription
SVGContentRandom SVG path.