-
Notifications
You must be signed in to change notification settings - Fork 2
Add RandomFrom
overloads
#21
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
Comments
I've created a function RandomString(const SL: TStrings): string; overload;
begin
if SL.Count = 0 then
raise ERangeError.Create('RandomString called with empty string list');
Result := SL[Random(SL.Count)];
end; |
Note that Delphi 12 now has the following overloads, so we don't need the Cardinal and TBytes overloads anymore: function RandomFrom(const AValues: array of ShortInt): ShortInt; overload;
function RandomFrom(const AValues: array of SmallInt): SmallInt; overload;
function RandomFrom(const AValues: array of Integer): Integer; overload;
function RandomFrom(const AValues: array of Int64): Int64; overload;
function RandomFrom(const AValues: array of Byte): Byte; overload;
function RandomFrom(const AValues: array of Word): Word; overload;
function RandomFrom(const AValues: array of Cardinal): Cardinal; overload;
function RandomFrom(const AValues: array of UInt64): UInt64; overload;
function RandomFrom(const AValues: array of Single): Single; overload;
function RandomFrom(const AValues: array of Double): Double; overload;
function RandomFrom(const AValues: array of Extended): Extended; overload;
function RandomFrom(const AValues: array of Boolean): Boolean; overload; |
This routine has its own issue: #28. |
There are so many overloads of Therefore this issue is being rejected and closed. |
There are
RandomFrom
functions inSystem.Math
for all the Float array types +Integer
,Int64
andUInt64
arrays.There also
RandomFrom
functions inSystem.AnsiStrings
andSystem.StrUtils
for arrays of ANSI and Unicode strings.What's missing are
RandomFrom
overloads forCardinal
arrays (+ shorter Integer types),TBytes
andTStrings
.The text was updated successfully, but these errors were encountered: