/** * 随机字符串 * @param $lenth * @return string */ public function randStr($lenth){ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $password = ''; for ($i = 0; $i < $lenth; $i++) { $password .= $chars[mt_rand(0, strlen($chars) - 1)]; } return $password; }
//调用
public function index(){
$str = $this->randStr(30);
dd($str);
}