1``random``
2==========
3
4.. versionadded:: 1.5
5    The ``random`` function was added in Twig 1.5.
6
7.. versionadded:: 1.6
8    String and integer handling was added in Twig 1.6.
9
10.. versionadded:: 1.38
11    The "max" argument was added in Twig 1.38.
12
13The ``random`` function returns a random value depending on the supplied
14parameter type:
15
16* a random item from a sequence;
17* a random character from a string;
18* a random integer between 0 and the integer parameter (inclusive).
19* a random integer between the integer parameter (when negative) and 0 (inclusive).
20* a random integer between the first integer and the second integer parameter (inclusive).
21
22.. code-block:: jinja
23
24    {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #}
25    {{ random('ABC') }}                         {# example output: C #}
26    {{ random() }}                              {# example output: 15386094 (works as the native PHP mt_rand function) #}
27    {{ random(5) }}                             {# example output: 3 #}
28    {{ random(50, 100) }}                       {# example output: 63 #}
29
30Arguments
31---------
32
33* ``values``: The values
34* ``max``: The max value when values is an integer
35
36.. _`mt_rand`: https://secure.php.net/mt_rand
37