随机数生成类

属性
命名空间 fize\math
类名 Random
方法:
方法名 说明
alnum() 生成数字和字母
alpha() 仅生成字符
numeric() 生成指定长度的随机数字
nozero() 数字和字母组合的随机字符串
uniqid() 基于以微秒计的当前时间,生成一个唯一的 ID
md5() 生成一个唯一的 MD5 值
sha1() 生成一个唯一的 SHA1 值
lottery() 根据数组元素的概率获得键名
uuid() 获取全球唯一标识

方法

alnum()

生成数字和字母

public static function alnum (
    int $len = 6
) : string
参数:
名称 说明
len 长度

alpha()

仅生成字符

public static function alpha (
    int $len = 6
) : string
参数:
名称 说明
len 长度

numeric()

生成指定长度的随机数字

public static function numeric (
    int $len = 4
) : string
参数:
名称 说明
len 长度

nozero()

数字和字母组合的随机字符串

public static function nozero (
    int $len = 4
) : string
参数:
名称 说明
len 长度

uniqid()

基于以微秒计的当前时间,生成一个唯一的 ID

public static function uniqid () : string

md5()

生成一个唯一的 MD5 值

public static function md5 () : string

sha1()

生成一个唯一的 SHA1 值

public static function sha1 () : string

lottery()

根据数组元素的概率获得键名

public static function lottery (
    array $ps,
    int $num = 1,
    bool $unique = true
) : mixed
参数:
名称 说明
ps array(‘p1’=>20, ‘p2’=>30, ‘p3’=>50);
num 默认为1,即随机出来的数量
unique 默认为true,即当num>1时,随机出的数量是否唯一
返回值:

当num为1时返回键名,反之返回一维数组

uuid()

获取全球唯一标识

public static function uuid () : string