- Notifications
You must be signed in to change notification settings - Fork2
Open
Description
Such a function was suggested by@Thaddy in#28 (comment).
A series of overloaded functions, something like the following might do the job (written off the top of my head - not compiled or tested 🤞):
procedureRandomiseStrings(const AList: TStringList); overload;begin AList.CustomSort( function(L: TStringList; A, B: Integer): Integerbegin// becomes -1, 0 or 1 Result := Random(3) -1;end );end;
and a string array version:
functionRandomiseStrings(const AArray:arrayof string): TArray<string>; overload;beginvar SL := TStringList.Create;tryforvar Sin AArraydo SL.Add(S); RandomiseStrings(SL); Result := SL.ToStringArray;finally SL.Free;end;end;
It's a shame thatTStrings doesn't implementCustomSort - it would have made the routine more general.
Maybe:
procedureRandomiseStrings(const AList: TStrings); overload;beginvar SL := TStringList.Create;try SL.Assign(AList); RandomiseStrings(SL); AList.Assign(SL);finally SL.Free;end;end;
Metadata
Metadata
Assignees
Projects
Status
Accepted