Routine that creates ordered ID

0

I need to perform a function that returns a string of 12 alphanumeric characters (base 62 for example). Leave it neat (example GenIDNew () -> aaaaa..a , next time you run - > aaaaa..c , the following - & gt ; aaaaa..h , etc. In Delphi I've set this up:

    function GenIDNuevo: string;
    var
       iVal1:   byte;
       iVal2:   byte;
       iChar:   integer;
       iCont:  integer;
       sStr:    string;
       sParte1: string;
       sParte2: string;
       dtAhora: TDateTime;
       iDays, iHour, iMinute, iSecond, iSeconds: Extended;
       dtInicio: TDateTime;
       ID: TGuid;
       sId:String;
    begin
       dtAhora := Now;
       CoCreateGuid(ID);

      sId := IntToStr(Length(GuidToString(ID)));


       sStr := LimpiaStr( sID );

       sParte2 := RightStr( sStr, 16 );

       sParte1 := LeftStr( sParte2, 8 );
       sParte2 := RightStr( sParte2, 8 );


       // Tomamos los dos conjuntos de caracteres y los 'fusionamos'
       sStr := '';
       for iCont := 1 to 8 do
       begin
          iVal1 := HEXtoByte( sParte1[ iCont ] );
          iVal2 := HEXtoByte( sParte2[ iCont ] );
          iChar := iVal1 XOR iVal2;
          sStr := sStr + sLetras2[ iChar + 1 ];
       end;


       dtInicio := EncodeDate( 2017, 02, 18 );
       iDays := Trunc( dtAhora - dtInicio );
       iHour := StrToInt( FormatDateTime( 'hh', dtAhora ) );
       iMinute := StrToInt( FormatDateTime( 'nn', dtAhora ) );
       iSecond := StrToInt( FormatDateTime( 'ss', dtAhora ) );
       iSeconds := ( iDays * 24 * 60 * 60 ) + ( iHour * 60 * 60 ) + ( iMinute * 60 ) + iSecond;

       sStr := LimpiaStr( sID );
       sStr := RightStr( sStr, 8 );






       sStr := ConvertirBase2Base(sStr,16,10,10); // lo paso de Base 16 a base 10
       sStr := FormatFloat( '0000000000', StrToInt64(sStr) );



       //Unimos con el decimal anterior
       sStr :=  FormatFloat( '0000000000', iSeconds ) + sStr;

       sStr :=  ConvertirBase2Base(sStr,10,62,11); // lo paso de Base 10 a base 62
       Result := 'q' + sStr; // le añando la primer aletra no utilizado por el anterior makeId



end;

But when doing tests with load, it is repeated in the same tenth of a second or before.

Does anyone think of something? Thanks.

    
asked by Carlos Vieites 21.09.2018 в 17:45
source

0 answers