delphi 随机生成汉字


本文整理自网络,侵删。

 

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,
国个一中

相关阅读 >>

Delphi 数字签名添加器源码

Delphi中用idhttp获取json数据乱码问题

Delphi firedac fdconnection 事务

Delphi整理八(对话框)

Delphi 屏幕截图完美解决方案

Delphi 如何获取进程的全路径名

Delphi 只用一条语句就能使tbitmap反色

Delphi 记录鼠标点击坐标

Delphi memo 自动滚动到最底下

Delphi获取优盘的id

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...