Si es aleatoria entonces será una cadena de texto, no?
Código Delphi
[-]
function DameClave( iLongitud:integer; iTipo:integer=1 ) : string;
const
cValoresNum = '0123456789';
cValoresAlpha = 'abcdefghijklmnopqrstuvwxyz';
cValoresAlphaNum = cValoresNum + cValoresAlpha;
var
iX : integer;
begin
Result := '';
Randomize;
case iTipo of
0 : for iX := 1 to iLongitud do
Result := Result + cValoresNum[ Random(length(cValoresNum))+1 ];
1 : for iX := 1 to iLongitud do
Result := Result + cValoresAlpha[ Random(length(cValoresAlpha))+1 ];
2 : for iX := 1 to iLongitud do
Result := Result + cValoresAlphaNum[ Random(length(cValoresAlphaNum))+1 ];
end;
end;
Y para llamarla está claro, le dices la longitud y el tipo.