Was mir als erstes auffällt, ist:
- in der for-schleife fehlt das begin/end (so wird nur x-mal select aber kein Text gesetzt!)
- anzahl kann einen Wert von 1..4 annehmen
- select := random(anzahl) hat somit einen Wert von 0..(anzahl-1)
- du fragst allerdings select auf 1..4 ab
- select = 4 wird nie vorkommen
- select = 0 ignorierst du
Da du ja selbst zugestehst, daß der Code "sub-optimal" ist, hier eine Anregung:
statt 4 separater Arrays würde ich einen einzelnen String nehmen und die selektierten CharSets einfach als Strings anfügen:
Delphi-Quellcode:
SourceChars := '';
if big.Checked then
SourceChars := SourceChars + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if small.Checked then
SourceChars := SourceChars + 'abcdefghijklmnopqrstuvwxyz';
...
if SourceChars = '' then begin
ShowMessage('Please select the wanted properties!');
exit;
end;
randomize;
resultString := '';
anzahl := StrToInt(repeat1.Text);
for i := 1 to anzahl do begin // !!!
select := random(length(SourceChars)) + 1;
resultString := resultString + SourceChars[select]; // besser als ständig in das Edit-Feld zu schreiben
end;
edit1.Text := resultString;