blob: aac2986c387271deb60e701570e195b1687830b7 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``random``
2==========
3
4The ``random`` function returns a random value depending on the supplied
5parameter type:
6
7* a random item from a sequence;
8* a random character from a string;
9* a random integer between 0 and the integer parameter (inclusive).
10* a random integer between the integer parameter (when negative) and 0 (inclusive).
11* a random integer between the first integer and the second integer parameter (inclusive).
12
13.. code-block:: twig
14
15 {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #}
16 {{ random('ABC') }} {# example output: C #}
17 {{ random() }} {# example output: 15386094 (works as the native PHP mt_rand function) #}
18 {{ random(5) }} {# example output: 3 #}
19 {{ random(50, 100) }} {# example output: 63 #}
20
21Arguments
22---------
23
24* ``values``: The values
25* ``max``: The max value when values is an integer