原文写于2010-11-03 18:29:20,网易博客,已删.
要在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 -i randomnum=$RANDOM*$scale/32767
同样,要使用declare,必须是在bash环境中.
2011-07-02 补充:
shell第一行必须是#!/usr/bin/bash