mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Added "Shuffle" to sqids_showcase
This commit is contained in:
parent
43478dbdbf
commit
cf08f46555
@ -54,16 +54,18 @@ object MainForm: TMainForm
|
||||
Top = 104
|
||||
Width = 449
|
||||
Height = 45
|
||||
Max = 20
|
||||
TabOrder = 1
|
||||
OnChange = TrackBarMinLengthChange
|
||||
end
|
||||
object btnShuffle: TButton
|
||||
Left = 463
|
||||
Left = 462
|
||||
Top = 40
|
||||
Width = 75
|
||||
Height = 29
|
||||
Caption = 'Shuffle'
|
||||
TabOrder = 2
|
||||
OnClick = btnShuffleClick
|
||||
end
|
||||
object PageControl1: TPageControl
|
||||
Left = 8
|
||||
|
@ -32,6 +32,7 @@ type
|
||||
procedure btnEncodeClick(Sender: TObject);
|
||||
procedure TrackBarMinLengthChange(Sender: TObject);
|
||||
procedure btnDecodeClick(Sender: TObject);
|
||||
procedure btnShuffleClick(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
@ -73,6 +74,33 @@ begin
|
||||
EditSqidsOutput.Text := lSqids.Encode(lIntegers);
|
||||
end;
|
||||
|
||||
function GetScrambled(const Alphabet: String): String;
|
||||
var
|
||||
I: Integer;
|
||||
lIdx1: Integer;
|
||||
lSize: Integer;
|
||||
lIdx2: Integer;
|
||||
lTmp: Char;
|
||||
begin
|
||||
Randomize;
|
||||
Result := Alphabet;
|
||||
lSize := Length(Result);
|
||||
for I := 1 to 100 do
|
||||
begin
|
||||
lIdx1 := Random(lSize) + 1;
|
||||
lIdx2 := Random(lSize) + 1;
|
||||
lTmp := Result[lIdx1];
|
||||
Result[lIdx1] := Result[lIdx2];
|
||||
Result[lIdx2] := lTmp;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMainForm.btnShuffleClick(Sender: TObject);
|
||||
begin
|
||||
EditAlphabet.Text := GetScrambled(EditAlphabet.Text);
|
||||
end;
|
||||
|
||||
procedure TMainForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
PageControl1.ActivePageIndex := 0;
|
||||
|
Loading…
Reference in New Issue
Block a user