randomInt

randomInt(max)

randomInt(min, max)

randomInt(size)

randomInt(size, max)

randomInt(size, min, max)

Try it yourself:

See also:

randomInt(): Random Integer Selection

randomInt() generates a pseudo-random integer in its requested bounds. It suits dice-like simulations, selecting an index, and discrete test cases.

Bound conventions

Check whether your intended endpoints are included and test boundary cases. Bounds should be integer values; use floor() or ceil() deliberately if raw limits originate from decimal calculations. Do not use round() on random() as a substitute, because it can bias endpoint probabilities.

For selecting from a collection, ensure the result matches valid indices and confirm length using size(). Reproducibility still matters for tests and simulations.

Try Random Int in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions