{rand:min:max}

Description

Returns a random integer between min and max, inclusive of both ends - the AA counterpart of PHP random_int(). Both bounds are required as integers; a non-numeric or empty bound is read as 0, and any trailing non-digit characters in a bound are dropped (so 7abc is read as 7). When min equals max the result is fixed at that single value. The output is never cached and is recomputed on every render, so it changes each time the page is built. Use it for picking a random item, rotating a banner, or jittering a cache key; for a random text token use randomstring instead.

Parameters

min required default 0

The lower bound. Read as an integer; an empty or non-numeric value is 0. When min equals max the result is fixed at that value.

max required default 0

The upper bound. Read as an integer; an empty or non-numeric value is 0. When max equals min the result is fixed at that value.

Examples

virtual{rand:0:100}
Expected(a random integer from 0 to 100, e.g. 42)
Actual5
A common range for a random percentage or a cache-busting jitter. Both ends are reachable, so 0 and 100 can occur.
test{rand:5:5}
Expected5
Actual5
When min and max are the same, the range has one member, so the result is always that value. This makes the otherwise-random command deterministic.
test{rand:}
Expected0
Actual0
With no bounds both min and max default to 0, so the result is 0. An empty bound is read as the integer 0.
virtual{switch:{rand:1:3}:1:red:2:green:3:blue}
Expected(red, green, or blue at random)
Actualgreen
Combine rand with switch to choose one option at random. rand picks 1, 2 or 3 and switch maps it to a label. Output varies on every render.
virtual{rand:1:6}
Expected(a random integer from 1 to 6, e.g. 4)
Actual4
Picks a whole number from 1 to 6, inclusive. The result is recomputed on every render, so it changes each time the page is built - a die roll.
test{rand:7abc:7abc}
Expected7
Actual7
A bound is read as an integer: any trailing non-digit characters are dropped, so 7abc is read as 7. Here both bounds become 7, giving a fixed 7.