<?php /* By Andreas Diegues Por Andreas Diegues */ function randCode($codeTotalChars) { for($i = 0; $i < $codeTotalChars; $i++) { $type[1] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|X|W|Y|Z"; $type[2] = "0|1|2|3|4|5|6|7|8|9"; $randType = rand(1, 2); $type = explode("|", $type[$randType]); $max = count($type); $randChar = rand(0, $max); $code .= $type[$randChar]; } return $code; } echo randCode(30); # echo randCode(8); >> A 8 chars code # echo randCode(8); >> Um c�digo de 8 caracteres ?>