View Full Version : TStringArray.Randomize()
Couldn't find anything like this, relatively simple and works for any array (probably). Let me know what I did wrong!
function tStringArray.randomize(): tStringArray;
var
i:integer;
begin
for i:=0 to high(self) do
_swap(self[i], self[random(low(self), high(self))], 2);
exit(self);
end;
Obscurity
01-14-2016, 02:46 AM
From ogLivid:
function tStringArray.shuffle():tStringArray;
var
vIndex:int32;
begin
for vIndex:=high(result:=self) downto 0 do
system.swap(result[vIndex],result[random(vIndex+1)]);
exit(result);
end;
Main difference, that one ^ will not alter the original array.
Laquisha
01-14-2016, 03:07 AM
Couldn't find anything like this
https://github.com/SRL/SRL-6/blob/master/lib/utilities/types/integerarrays.simba#L523
https://github.com/SRL/SRL-6/blob/master/lib/utilities/types/integerarrays.simba#L523
Knew it was in there somewhere, gave up after like 15 minutes.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.