function rs($u) { $min = pow(10, $u - 1); $max = pow(10, $u) - 1; return mt_rand($min, $max); } echo rs(11);