随机函数这样写:
function TForm1.HanShu(InputString: String): String;
//InputString :输入字符串;
//RESULT : 返回字符串;
Var
a : Array Of Char;
Temp : Char;
i, FromSit, ToSit ,StrLength: Integer;
begin
Randomize;
StrLength := Length(InputString);
SetLength(a,StrLength);
For i := 1 To StrLength Do
a[i-1] := InputString[i];
//随机交换关联序号
For i := 0 To StrLength-1 Do
Begin
//生成随机数
FromSit := Random(StrLength);
ToSit := Random(StrLength);
//交换序号
Temp := a[FromSit];
a[FromSit] := a[ToSit];
a[ToSit] := Temp;
End;
For i := 1 To StrLength Do
InputString[i] := a[i-1];
Result := InputString;
end;
然后再比较字符串是否相同;也就是说字符串是否相等!!
OK!!!!!!!!
randomize;
s2 := '';
for i := 0 to l1 do
begin
if i= 0 then
begin
s2 := s2 + s1[i];
break;
end;
j := random(l1-i);
s2 := s2 + s1[j];
s1[j] := s1[l1-i];
end;