ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# `random` New in version 1.5: The `random` function was added in Twig 1.5. New in version 1.6: String and integer handling was added in Twig 1.6. The `random` function returns a random value depending on the suppliedparameter type: - a random item from a sequence; - a random character from a string; - a random integer between 0 and the integer parameter (inclusive). <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3 4</pre></div></td><td class="code"><div class="highlight"><pre>{{ 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 #} </pre></div></td></tr></table> ### Arguments - `values`: The values