1. 程式人生 > >php生成隨機長度字串

php生成隨機長度字串

php生成隨機長度字串

只要穿長度的引數就行了,具體程式碼如下:

	public function getRandStr($len) //len字串長度
	{
	    $chars = array(
	        'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9');//你想填寫的隨機數
	    $charsLen = count($chars) - 1;
	    shuffle($chars);
	    $output = '';
	    for ($i = 0; $i < $len; $i++) {
	        $output .= $chars[mt_rand(0, $charsLen)];
	    }
	    return $output;
	}