在shell中生成随机数,在bash脚本中可以调用$RANDOM。
找到一段对$random的介绍文字:
Each time this is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset.
生成一个范围中的随机数:
使用declare,必须是在bash环境中。
补充:
shell第一行必须是#!/usr/bin/bash
shell生成随机数的一些例子:
shell随机数进阶: