diff --git a/samples/sqids_showcase/MainFormU.dfm b/samples/sqids_showcase/MainFormU.dfm index 4818dbab..14bdfae1 100644 --- a/samples/sqids_showcase/MainFormU.dfm +++ b/samples/sqids_showcase/MainFormU.dfm @@ -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 diff --git a/samples/sqids_showcase/MainFormU.pas b/samples/sqids_showcase/MainFormU.pas index 3d832cf6..1d42b11a 100644 --- a/samples/sqids_showcase/MainFormU.pas +++ b/samples/sqids_showcase/MainFormU.pas @@ -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;