Skip to content

Commit

Permalink
Added "Shuffle" to sqids_showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed May 23, 2024
1 parent 43478db commit cf08f46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion samples/sqids_showcase/MainFormU.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions samples/sqids_showcase/MainFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ TMainForm = class(TForm)
procedure btnEncodeClick(Sender: TObject);
procedure TrackBarMinLengthChange(Sender: TObject);
procedure btnDecodeClick(Sender: TObject);
procedure btnShuffleClick(Sender: TObject);
private
{ Private declarations }
public
Expand Down Expand Up @@ -73,6 +74,33 @@ procedure TMainForm.btnEncodeClick(Sender: TObject);
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;
Expand Down

0 comments on commit cf08f46

Please sign in to comment.