Hello, I'm trying to shuffle letters in Memo box. But random isn't working. Here's my code:
Randomize;
...
for I:=0 to Text_Mmo.Lines.Count do
begin
StrPtr^:=Token^.GetTok(Text_Mmo.Lines[I], I + 1, ' ');
Len^:=Length(StrPtr^);
if (Len^ >= 2) then
begin
SetLength(Arr, Len^);
// Array ata
for J:=0 to Len^ do
begin
Arr[J + 1]:=StrPtr^[J];
end;
for J:=1 to Len^ do
begin
RandNum^:=Random(Len^);
// ShowMessage(RandNum^.ToString);
while RandNum^ = J do
begin
RandNum^:=Random(Len^);
end;
Arr[J]:=StrPtr^[RandNum^ - 1];
end;
ShowMessage(ArrayToString(Arr)); // This outputs Hello and then world!
end;
end;
function TForm1.ArrayToString(charArray: array of char): string;
var
I : Integer;
begin
// Result := 'a';
for I := Low(CharArray) to High(CharArray) do
Result := Result + CharArray[I];
end;
How can I randomize a char of array?