{randomstring:len}

Description

Returns a random string of the given length. The character set is fixed: 57 characters - lowercase a to x without q, y and z (23 letters), uppercase A to X without Y and Z (24 letters), and the digits 0 to 9. It is not a full alphabet, so do not use the result where every letter or a specific case must be possible. The output is regenerated on every render (the command is never cached), so the same template yields a different value each time and cannot be a deterministic test on its own. The length is the only argument and is read as a whole number: with no length, a zero or negative length, or text that does not start with a digit, the result is the empty string, and a length over 1000 gives 1000 characters. Until November 2026 a non-numeric length such as the word abc looped endlessly and exhausted memory, so on an install not updated since pass a literal positive integer. The characters come from the PHP mt_rand generator, whose values can be predicted from earlier output - fine for element ids or cache-busting parameters, but never use it for passwords, access codes or form tokens. For a configurable generator with more options see the AA_Generator_Rnd class.

Parameters

len optional default empty (no characters)

The number of characters to generate, read as a whole number and capped at 1000. With no value, 0, a negative number or text that does not start with a digit the result is the empty string. Until November 2026 a non-numeric word (for example abc) caused an endless loop that exhausted memory, so on an install not updated since pass a literal positive whole number.

Examples

test[{randomstring:abc}] {strlen:{randomstring:5000}}
Expected[] 1000
Actual[] 1000
A length that does not start with a digit gives nothing, and a length over 1000 gives 1000 characters, so no template can exhaust the memory of the server. Until November 2026 the word abc looped endlessly and 5000 gave 5000 characters.
virtual{randomstring:8}
ExpectedaK3xR9pW (8 random characters, different each render)
Actual6wNKkBtN
The single argument is the length. {randomstring:8} returns 8 characters drawn from the fixed 57-character set. The value changes on every render, so it is shown here as an illustrative sample, not an asserted result.
virtual{randomstring:16}
Expected7mTQ2haK0xR4pBwf (16 random characters, different each render)
ActualONJfxAGGdBficKTO
A larger length produces more characters. {randomstring:16} returns 16 characters. Use a length that matches the strength you need (longer is harder to guess).
test{strlen:{randomstring:12}}
Expected12
Actual12
Although the characters are random, the length is exact, so it can be checked. Wrapping the call in {strlen:...} always returns the requested length (here 12). This is the deterministic, testable property of the command.
test[{randomstring:}] [{randomstring:0}]
Expected[] []
Actual[] []
With no length, or a length of 0, nothing is generated and the result is the empty string. The brackets here only frame the empty output so it is visible.
virtual<div id="map-{randomstring:6}"></div>
Expected(a div with a random id such as map-aK3xR9, so two maps on one page never share an id)
Actual
A typical use: several copies of one widget on a page need different element ids. Do not use randomstring for passwords, access codes or form tokens - its values can be predicted (see the description).
virtual{randomstring:40}
ExpectedvjCSde5LgAOdJncfEDepfMEd5NhoRROdNOCdocM7 (no q, y, z, Y or Z ever appears)
ActualGJh3BIQ6H52skFkru2UV02kXXPsousGtAImBpbiS
The character set is not a full alphabet. It omits lowercase q, y and z and uppercase Y and Z, so those five letters never appear in the output. Do not rely on the result to contain every letter or to be evenly distributed across the whole alphabet.