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:
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.
argument
description
min
Lower boundary, or upper if max is not given.
max
Upper boundary.
n
Number of floats to generate.
returns
description
number, Array
Single 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.
argument
description
min
Lower boundary, or upper if max is not specified.
max
Upper boundary.
n
Number of integers to generate.
returns
description
number, Array
Single integer or array of random integers.
choice
dice.core.choice(values[, n])
Samples some elements with replacement from an array with uniform distribution.
argument
description
values
Array to sample from.
n
Number of elements to sample.
returns
description
object, Array
Single 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.
argument
description
string
String to sample characters from.
n
Number of characters to sample.
returns
description
string, Array
Random 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.
argument
description
values
Array 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.
argument
description
p
Bias (probability of head).
head
Head value.
tail
Tail value.
n
Number of coins to flip.
returns
description
object, Array
Object 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.
argument
description
min
Lower boundary.
max
Upper boundary.
n
Number of values to return.
returns
description
number, Array
Single value or array of random values.
exponential
dice.dist.exponential(lambda[, n])
Generates some exponentially distributed random values.
argument
description
lambda
Rate parameter.
n
Number of values to return.
returns
description
number, Array
Single value or array of random values.
pareto
dice.dist.pareto(xmin, alpha[, n])
Generates some Pareto distributed random values.
argument
description
xmin
Scale parameter.
alpha
Shape parameter.
n
Number of values to return.
returns
description
number, Array
Single value or array of random values.
boundedPareto
dice.dist.boundedPareto(xmin, xmax, alpha[, n])
Generates some bounded Pareto distributed random values.
argument
description
xmin
Lower boundary.
xmax
Upper boundary.
alpha
Shape parameter.
n
Number of values to return.
returns
description
number, Array
Single value or array of random values.
normal
dice.dist.normal(mu, sigma[, n])
Generates some normally distributed random values.
argument
description
mu
Location parameter (mean).
sigma
Squared scale parameter (variance).
n
Number of values to return.
returns
description
number, Array
Single value or array of random values.
lognormal
dice.dist.lognormal(mu, sigma[, n])
Generates some log-normally distributed random values.
argument
description
mu
Location parameter.
sigma
Scale parameter.
n
Number of values to return.
returns
description
number, Array
Single value or array of random values.
weibull
dice.dist.weibull(lambda, k[, n])
Generates some Weibull distributed random values.
argument
description
lambda
Scale parameter.
k
Shape parameter.
n
Number of values to return.
returns
description
number, Array
Single 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
argument
description
lambda
Mean of the distribution.
n
Number of values to return.
returns
description
number, Array
Single 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.
property
description
i
Object corresponding to the CSS content. Can be a single string, an array, etc.
o
String 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.
returns
description
CSSContent
Random CSS integer.
number
dice.css.number()
Generates a random CSS number.
returns
description
CSSContent
Random CSS number.
length
dice.css.length()
Generates a random CSS length.
returns
description
CSSContent
Random CSS length.
opacityValue
dice.css.opacityValue()
Generates a random CSS opacity-value.
returns
description
CSSContent
Random CSS opacityValue.
color
dice.css.color()
Generates a random CSS color.
returns
description
CSSContent
Random 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.
property
description
i
Object corresponding to the SVG content. Can be a single string, an array, etc.
o
String representation of the SVG content. This is the final value that is put after the colon in a property:value pair.