Random
random
A uniform random number in [0, 1); random(n) gives n of them. In the playground every Run starts from a fresh random seed, so the numbers change each time; in .apc pages and their PDFs the seed is fixed, so a worksheet and its answer key always show the same numbers. seed(n) makes any run repeatable.
n (integer) -- optional: how many draws (gives an array)
randInt
A random whole number from lo to hi, both included; randInt(lo, hi, n) gives n of them. See random() for how seeding works.
lo (integer) --
hi (integer) --
n (integer) -- optional: how many draws (gives an array)
randDecimal
A random exact number from lo to hi in steps of step, both ends included: randDecimal(1.5, 9.5, 0.5) is one of 1.5, 2, 2.5, ..., 9.5, and 2.5 is exactly 5/2, so everything computed from it stays exact. Use it for question-template values (not randUniform, whose draws are decimals like 4.623167737). The step can be any fraction (randDecimal(1, 2, 1/3)); hi - lo must be a whole number of steps. randDecimal(lo, hi, step, n) gives n draws. See random() for how seeding works.
lo (number) --
hi (number) --
step (number) --
n (integer) -- optional: how many draws (gives an array)
seed
Restarts the script's random stream from n: the same seed always gives the same draws, in the playground, .apc pages and PDFs alike. Without it, the playground uses a fresh seed on every Run and .apc pages a fixed one.
choose
One item picked at random from a list -- numbers (kept exact), text or anything else: choose([9.8, 10]), choose(["ball", "stone"]). choose(xs, n) picks n (with replacement). See random() for how seeding works.
xs (array) --
n (integer) -- optional: how many draws (gives an array)
shuffle
A randomly shuffled copy of a list (numbers, text or anything else). See random() for how seeding works.
sample
k different items of a list (numbers, text or anything else), in random order (without replacement). See random() for how seeding works.
xs (array) --
k (integer) --
randIndex
A random index, chosen with probability proportional to the weights; randIndex(ws, n) gives n. See random() for how seeding works.
weights (array) --
n (integer) -- optional: how many draws (gives an array)
randUniform
A random draw from the continuous uniform distribution; a trailing n gives n draws as an array. See random() for how seeding works. The draw is a decimal approximation (4.623167737...): for exact question values use randDecimal.
lower (number) --
upper (number) --
n (integer) -- optional: how many draws (gives an array)
randBernoulli
A random draw from the Bernoulli (true/false; 1/0 in an array) distribution; a trailing n gives n draws as an array. See random() for how seeding works.
p (number) --
n (integer) -- optional: how many draws (gives an array)
randBinomial
A random draw from the binomial distribution; a trailing n gives n draws as an array. See random() for how seeding works.
trials (integer) --
p (number) --
n (integer) -- optional: how many draws (gives an array)
randPoisson
A random draw from the Poisson distribution; a trailing n gives n draws as an array. See random() for how seeding works.
lambda (number) --
n (integer) -- optional: how many draws (gives an array)
randNegBinomial
A random draw from the negative binomial (failures before the r-th success) distribution; a trailing n gives n draws as an array. See random() for how seeding works.
successes (integer) --
p (number) --
n (integer) -- optional: how many draws (gives an array)
randHypergeometric
A random draw from the hypergeometric distribution; a trailing n gives n draws as an array. See random() for how seeding works.
population (integer) --
marked (integer) --
draws (integer) --
n (integer) -- optional: how many draws (gives an array)
randGeometric
A random draw from the geometric distribution; a trailing n gives n draws as an array. See random() for how seeding works.
p (number) --
n (integer) -- optional: how many draws (gives an array)
randExponential
A random draw from the exponential distribution; a trailing n gives n draws as an array. See random() for how seeding works.
lambda (number) --
n (integer) -- optional: how many draws (gives an array)
randNormal
A random draw from the normal distribution; a trailing n gives n draws as an array. See random() for how seeding works.
mu (number) --
sigma (number) --
n (integer) -- optional: how many draws (gives an array)
randGamma
A random draw from the gamma distribution; a trailing n gives n draws as an array. See random() for how seeding works.
shape (number) --
scale (number) --
n (integer) -- optional: how many draws (gives an array)
randBeta
A random draw from the beta distribution; a trailing n gives n draws as an array. See random() for how seeding works.
alpha (number) --
beta (number) --
n (integer) -- optional: how many draws (gives an array)
randChiSquare
A random draw from the chi-square distribution; a trailing n gives n draws as an array. See random() for how seeding works.
df (number) --
n (integer) -- optional: how many draws (gives an array)
randLognormal
A random draw from the lognormal distribution; a trailing n gives n draws as an array. See random() for how seeding works.
mu (number) --
sigma (number) --
n (integer) -- optional: how many draws (gives an array)
randStudentT
A random draw from the Student's t distribution; a trailing n gives n draws as an array. See random() for how seeding works.
df (number) --
n (integer) -- optional: how many draws (gives an array)
randF
A random draw from the F distribution; a trailing n gives n draws as an array. See random() for how seeding works.
df1 (number) --
df2 (number) --
n (integer) -- optional: how many draws (gives an array)
monteCarlo
Monte Carlo estimate of the integral of f over [a, b] from n random samples, with its standard error.
f (expression) --
x (name) --
a (number) --
b (number) --
n (integer) --