/
lasersquad
/
DynamicArrays
Обзор
Документация
Войти
/
lasersquad
/
DynamicArrays
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
dynamicarrays/prj/Delphi/DynamicArraysOTests/DynamicArraysUtils.pas
79 строк
2 KB
lasersquad0
new files
20 май 2026, 22:15
20 май 2026, 22:15
b70be5f
Код
Авторство
О чём код?
unit DynamicArraysUtils; interface function GenerateRandomStr(const ALength: Integer): string; overload; function GenerateRandomStrW(const ALength: Integer): WideString; overload; function MillisecToStr(ms: Cardinal): string; implementation uses SysUtils; function MillisecToStr(ms: Cardinal): string; var milliseconds: Cardinal; seconds: Cardinal; minutes: Cardinal; hours: Cardinal; begin milliseconds := ms mod 1000; seconds := (ms div 1000) mod 60; minutes := (ms div 60000) mod 60; hours := (ms div 3600000) mod 24; //char buf[100]; if hours > 0 then Result := Format('%u h %u min %u sec %u ms', [hours, minutes, seconds, milliseconds]) else if minutes > 0 then Result := Format('%u min %u sec %u ms', [minutes, seconds, milliseconds]) else Result := Format('%u sec %u ms', [seconds, milliseconds]); end; function GenerateRandomStr(const ALength: Integer): string; const // list of symbols available for string generation sChars = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; Len = Length(sChars); var i, RandIndex: Integer; begin Result := ''; if ALength <= 0 then Exit; SetLength(Result, ALength); for i := 1 to ALength do begin // choose random symbol from the list RandIndex := Random(Len) + 1; Result[i] := sChars[RandIndex]; end; end; function GenerateRandomStrW(const ALength: Integer): WideString; const // list of symbols available for string generation sChars: WideString = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; var i, RandIndex: Integer; Len: Integer; begin Result := ''; if ALength <= 0 then Exit; Len := Length(sChars); SetLength(Result, ALength); for i := 1 to ALength do begin // choose random symbol from the list RandIndex := Random(Len) + 1; Result[i] := sChars[RandIndex]; end; end; end.