PDA

View Full Version : TStringArray.Randomize()



Ross
01-14-2016, 02:34 AM
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

Ross
01-14-2016, 04:08 AM
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.