mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-11 09:56:32 +00:00
22537dd1c4
* 2.x: Fix small typo Fix: Typo Enhancement: Use GithubActions instead of Travis for tests Fix: DOCtor-RST build Enhancement: Use no_explicit_use_of_code_block_php rule Fix: Highlighting Enhancement: Introduce DOCtor-RST config + Sphinx build + GithubActions Enhancement: Use GithubActions instead of Travis for tests Fix `odd` not working for negative numbers Bump version to 2.14.2-DEV Prepare the 2.14.1 release Update CHANGELOG Bump version to 1.44.2-DEV Prepare the 1.44.1 release
26 lines
962 B
ReStructuredText
26 lines
962 B
ReStructuredText
``random``
|
|
==========
|
|
|
|
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:: twig
|
|
|
|
{{ 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
|