random

这个 random 函数根据提供的参数类型返回随机值:

  • 序列中的随机项;
  • 字符串中的随机字符;
  • 一个介于0和整数参数之间的随机整数(包括0和整数参数)。
  • 一个介于整数参数(负数)和0(含0)之间的随机整数。
  • 第一个整数和第二个整数参数(包括)之间的随机整数。
1
2
3
4
5
{{ 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 #}

争论

  • values :值
  • max :值为整数时的最大值