Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``random`` |
| 2 | ========== |
| 3 | |
| 4 | The ``random`` function returns a random value depending on the supplied |
| 5 | parameter 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 | |
| 21 | Arguments |
| 22 | --------- |
| 23 | |
| 24 | * ``values``: The values |
| 25 | * ``max``: The max value when values is an integer |