random
random
函数根据提供的参数类型返回一个随机值
- 从序列中随机选择一个项目;
- 从字符串中随机选择一个字符;
- 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
:当 values 是整数时的最大值