From: Tobias Schultze Date: Thu, 26 Jan 2012 11:45:18 +0000 (+0100) Subject: updated doc for random function X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=faa90c926820c5e2649f4e5d0aa07529a3632eec;p=web%2Fkonrad%2Ftwig.git updated doc for random function --- diff --git a/CHANGELOG b/CHANGELOG index d5541a5..6ee60ab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ * added a date function to ease date comparison * fixed unary operators precedence * added recursive parsing support in the parser + * added string and integer handling for the random function * 1.5.1 (2012-01-05) diff --git a/doc/functions/random.rst b/doc/functions/random.rst index 4f62f49..c9eaf18 100644 --- a/doc/functions/random.rst +++ b/doc/functions/random.rst @@ -4,8 +4,20 @@ .. versionadded:: 1.5 The random function was added in Twig 1.5. -The ``random`` function returns a random item from a sequence: +.. versionadded:: 1.6 + String and integer handling was added in Twig 1.6. + +The ``random`` function returns a random value depending on the supplied paramter type: + +* a random item from a Traversable or array +* a random character from a string +* a random integer between 0 and the integer parameter (inclusive) .. code-block:: jinja - {{ random(['apple', 'orange', 'citrus']) }} + {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #} + {{ random('ABC') }} {# example output: C #} + {{ random() }} {# example output: 15386094 (works as native PHP `mt_rand`_ function) #} + {{ random(5) }} {# example output: 3 #} + +.. _`mt_rand`: http://php.net/mt_rand