Some times you want to generate Alpha Numeric , Numeric or Alphabetic digit for password or some kind of number. It can be 2 to 16 digit. For these problem i have a solutions:
function generateId($length, $type = 'ALPHANUMERIC') { if($type == 'ALPHANUMERIC') $chars = "12345CDEFGHI67890NOPQRSTU01492VWXYZ43210XYZFGH98765ABCDEF83574GHIJKLM09876QRSTUV54321"; else if($type == 'NUMERIC') $chars = "1234567890987654321678905432101928374651029384756162738495061728394055432167890"; $id = ""; while (strlen($id)<$length) { $id .= $chars{mt_rand(0,strlen($chars))}; } return $id; } generateId(12, 'ALPHANUMERIC');