var
aa: string;
bb: array[1..95] of byte;
cc: array[1..95] of byte;
i, j: integer;
begin
i := $A0;
for j := 1 to 95 do
begin
bb[j] := i;
cc[j] := i;
inc(i);
end;
Randomize;
for i := 1 to 3 do
begin
aa := aa + chr(bb[Random(95)]) + chr(cc[Random(95)]);
end;
Self.my1.Lines.Add(aa);
end;
function TfrmPWGenerate.btnGenerateClick(Sender: TObject): string;
{max length of generated password}
const
intMAX_PW_LEN = 10;
var
i: Byte;
s: string;
begin
{if you want to use the "A..Z" characters}
if cbAZ.Checked then
s := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
else
s := "";
{if you want to use the "a..z" characters}
if cbAZSmall.Checked then
s := s + "abcdefghijklmnopqrstuvwxyz";
{if you want to use the "0..9" characters}
if cb09.Checked then
s := s + "0123456789";
if s = "" then exit;
Result := "";
for i := 0 to intMAX_PW_LEN-1 do
Result := Result + s[Random(Length(s)-1)+1];
end;
initialization
Randomize;
结果:
IBbfA1mVK2
tmuXIuQJV5
oNEY1cF6xB
flIUhfdIui
mxaK71dJaq
B0YTqxdaLh
...
===================================
function GetRandomString:string;
var
len,I:byte;
Str:string;
begin
len:=random(100);//获取要随机生成字符的长度!
For I:=1 to len do
Str:=str+chr(random(128));
result:=str;
end;
procedure TForm1.btn8Click(Sender: TObject);
var
i,j,Ind:DWORD;
Target:string;
UseData:array[0..3] of Integer;
TempInd:Integer;
isInUse:BOOL;
IndStr:string;
begin
for j:=0 to 3 do
UseData[j]:=0;
Ind:=0;
while True do
begin
Randomize;
TempInd:=Random(5);
if TempInd =0 then Continue;
isInUse:=False;
for j:=0 to 3 do
begin
if UseData[j]=TempInd then
begin
isInUse:=True;
Break;
end;
end;
if not isInUse then
begin
UseData[Ind]:= TempInd;
inc(Ind);
end;
if Ind=4 then Break;
end;
Target :='';
for i:=0 to 3 do
begin
IndStr:=IndStr+inttostr(UseData[i])+',';
Target:= Target + Copy(edt1.text,UseData[i]*2-1,2);
end;
mmy1.lines.add(Format('%s',[IndStr]));
mmy1.Lines.Add(Format('%s',[Target]));
end;
效果:
3,2,4,1,
中个国一
2,3,4,1,
个中国一
3,1,2,4,
中一个国
4,2,3,1,
国个中一
2,4,1,3,
个国一中
2,4,3,1,
个国中一
1,4,2,3,
一国个中
2,1,4,3,
个一国中
4,2,1,3,
国个一中
1,2,3,4,
一个中国
2,4,3,1,
个国中一
4,2,3,1,
国个中一
1,3,2,4,
一中个国
4,2,1,3,
国个一中