Skip to content

Commit e314b6e

Browse files
committed
Add new RandomString function to string category
A new source code file was added for RandomString Meta data for RandomString was added to string.ini.
1 parent 3a69083 commit e314b6e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

collection/707.dat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function RandomString(const SL: Classes.TStrings): string; overload;
2+
begin
3+
if SL.Count = 0 then
4+
raise SysUtils.EArgumentException.Create(
5+
'RandomString called with empty string list'
6+
);
7+
Result := SL[Random(SL.Count)];
8+
end;

collection/string.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,3 +1807,14 @@ DelphiXE4=Y
18071807
Delphi10S=Y
18081808
Delphi12A=Y
18091809
FPC=Y
1810+
1811+
[RandomString]
1812+
DescEx="<p>Returns a random string from the given non-empty string list.</p><p>An <var>EArgumentException</var> exception is raised if the string list is empty.</p>"
1813+
Extra="<p>The Delphi RTL has a similar <var>RandomFrom</var> function in <var>StrUtils</var> that returns a random string from a string array.</p>"
1814+
Units=SysUtils,Classes
1815+
TestInfo=advanced
1816+
AdvancedTest.Level=unit-tests
1817+
AdvancedTest.URL="https://github.com/delphidabbler/code-snippets/tree/master/tests/Cat-String"
1818+
Snip=707.dat
1819+
DelphiXE=Y
1820+
Delphi12A=Y

0 commit comments

Comments
 (0)