NCDS
2010-09-06 16:03:57
First thing,
Second thing,
It was tested with:
Output:
Thoughts?
{*******************************************************************************
procedure DeleteValueInVarArray(var Arr: TVariantArray; ValuePosition: Integer);
By: EvilChicken!
Description: Deletes value with ValuePosition in "Arr" array.
*******************************************************************************}
procedure DeleteValueInVarArray(var Arr: TVariantArray; ValuePosition: Integer);
var
ArrLen, I: Integer;
begin
ArrLen := High(Arr);
for I := ValuePosition to ArrLen - 1 do
Swap(Arr[I], Arr[I + 1]);
SetArrayLength(Arr, ArrLen);
end;
The function is still EC!'s, all I did was change the data type. With this function however, the others may not really even be necessary? This function is tested and proven to work in the following function.Second thing,
{*******************************************************************************
function RandomizeArray(Objs: TVariantArray): TVariantArray;
By: NCDS & Coh3n
Description: Randomly arranges array 'Objs' and results the new array
*******************************************************************************}
function RandomizeArray(Objs: TVariantArray): TVariantArray;
var
i, o: Integer;
begin
SetLength(Result, Length(Objs));
while (Length(Objs) <> 0) do
for i := 0 to High(Result) do
begin
o := Random(Length(Objs));
Result[i] := Objs[o];
DeleteValueInVarArray(Objs, o);
end;
end;
This is something me and Coh3n were working on for MSI and figured it might work nice in SRL as well.It was tested with:
procedure DeleteValueInVarArray(var Arr: array of variant; ValuePosition: Integer);
var
ArrLen, I: Integer;
begin
ArrLen := High(Arr);
for I := ValuePosition to ArrLen - 1 do
Swap(Arr[I], Arr[I + 1]);
SetArrayLength(Arr, ArrLen);
end;
function RandomizeArray(Objs: TVariantArray): TVariantArray;
var
i, o: Integer;
begin
SetLength(Result, Length(Objs));
while (Length(Objs) <> 0) do
for i := 0 to High(Result) do
begin
o := Random(Length(Objs));
Writeln(Objs[o]);
Result[i] := Objs[o];
DeleteValueInVarArray(Objs, o);
Writeln('Length = ' + IntToStr(Length(Objs)));
end;
for i := 0 to High(Result) do
Writeln(Result[i]);
end;
var
arr: TVariantArray;
begin
ClearDebug;
arr := ['sh', 'ho', 'k', 'l', 'y'];
RandomizeArray(arr);
end.
Output:
'ho'
Length = 4
'y'
Length = 3
'l'
Length = 2
'k'
Length = 1
'sh'
Length = 0
'ho'
'y'
'l'
'k'
'sh'
Successfully executed.
Thoughts?