``random`` ========== .. versionadded:: 2.7 The "max" argument was added in Twig 2.7. The ``random`` function returns a random value depending on the supplied parameter type: * a random item from a sequence; * a random character from a string; * a random integer between 0 and the integer parameter (inclusive). * a random integer between the integer parameter (when negative) and 0 (inclusive). * a random integer between the first integer and the second integer parameter (inclusive). .. code-block:: jinja {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #} {{ random('ABC') }} {# example output: C #} {{ random() }} {# example output: 15386094 (works as the native PHP mt_rand function) #} {{ random(5) }} {# example output: 3 #} {{ random(50, 100) }} {# example output: 63 #} Arguments --------- * ``values``: The values * ``max``: The max value when values is an integer .. _`mt_rand`: https://secure.php.net/mt_rand
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
attribute.rst | File | 604 B | 0644 |
|
block.rst | File | 791 B | 0644 |
|
constant.rst | File | 487 B | 0644 |
|
country_timezones.rst | File | 799 B | 0644 |
|
cycle.rst | File | 548 B | 0644 |
|
date.rst | File | 1.06 KB | 0644 |
|
dump.rst | File | 1.56 KB | 0644 |
|
html_classes.rst | File | 899 B | 0644 |
|
include.rst | File | 2.24 KB | 0644 |
|
index.rst | File | 213 B | 0644 |
|
max.rst | File | 332 B | 0644 |
|
min.rst | File | 331 B | 0644 |
|
parent.rst | File | 563 B | 0644 |
|
random.rst | File | 1.05 KB | 0644 |
|
range.rst | File | 1.2 KB | 0644 |
|
source.rst | File | 694 B | 0644 |
|
template_from_string.rst | File | 888 B | 0644 |
|