]>
Commit | Line | Data |
---|---|---|
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 | The ``random`` function returns a random value depending on the supplied | |
11 | parameter type: | |
12 | ||
13 | * a random item from a sequence; | |
14 | * a random character from a string; | |
15 | * a random integer between 0 and the integer parameter (inclusive). | |
16 | ||
17 | .. code-block:: jinja | |
18 | ||
19 | {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #} | |
20 | {{ random('ABC') }} {# example output: C #} | |
21 | {{ random() }} {# example output: 15386094 (works as native PHP `mt_rand`_ function) #} | |
22 | {{ random(5) }} {# example output: 3 #} | |
23 | ||
24 | Arguments | |
25 | --------- | |
26 | ||
27 | * ``values``: The values | |
28 | ||
29 | .. _`mt_rand`: http://php.net/mt_rand |