Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new RandomString routine to String Management category #28

Open
delphidabbler opened this issue Oct 14, 2024 · 3 comments
Open

Add new RandomString routine to String Management category #28

delphidabbler opened this issue Oct 14, 2024 · 3 comments
Assignees
Labels
completed Issue completed and committed to develop. To be closed on next release enhancement New feature or request
Milestone

Comments

@delphidabbler
Copy link
Owner

Suggest new routine, with following attributes:

Decription

Returns a random string from the given string list, which must not be empty.

An ERangeError exception is raised if the string list is empty.

Source code

function RandomString(const SL: TStrings): string;
begin
  if SL.Count = 0 then
    raise ERangeError.Create('RandomString called with empty string list');
  Result := SL[Random(SL.Count)];
end;

Snippet type

Routine.

Category

String Management

Required units

SysUtils, Classes.

Required snippets

None.

XRefs

None.

Extra

None.

@delphidabbler delphidabbler self-assigned this Oct 14, 2024
@delphidabbler delphidabbler added considering Issue is currently under consideration enhancement New feature or request labels Oct 14, 2024
@github-project-automation github-project-automation bot moved this to Considering in Code Snippets Oct 14, 2024
@delphidabbler
Copy link
Owner Author

I have this function in my local Code Snippets user database in the User Defined Snippets category.

@delphidabbler
Copy link
Owner Author

The Delphi RTL has a similar routine that returns a random string from an array of strings, but not from a string list.

@delphidabbler delphidabbler added accepted Issue will be actioned and removed considering Issue is currently under consideration labels Apr 5, 2025
@delphidabbler delphidabbler moved this from Considering to Accepted in Code Snippets Apr 5, 2025
@delphidabbler delphidabbler added completed Issue completed and committed to develop. To be closed on next release and removed accepted Issue will be actioned labels Apr 5, 2025
@delphidabbler delphidabbler moved this from Accepted to Completed in Code Snippets Apr 5, 2025
@delphidabbler delphidabbler added this to the Next Release milestone Apr 5, 2025
@delphidabbler
Copy link
Owner Author

Implemented, with unit tests, by merge commit 15c7ce2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed Issue completed and committed to develop. To be closed on next release enhancement New feature or request
Projects
Status: Completed
Development

No branches or pull requests

1 participant