delphi 分享三个随机字符串


本文整理自网络,侵删。

 
uses math;

function GenID:String;
var
b, x: byte;
begin
  Result := '{';
  Randomize;
  for b:= 1 to 8 do
  begin
    if Random(100) > 50 then Result := Result + chr(RandomRange(48,57))
    else Result := Result + chr(RandomRange(65,90));
  end;
  Result := Result + '-';
  for x:= 1 to 3 do
  begin
    for b:= 1 to 4 do
    begin
      if Random(100) < 50 then Result := Result + chr(RandomRange(48,57))
      else Result := Result + chr(RandomRange(65,90));
    end;
    Result := Result + '-';
  end;
  for b:= 1 to 12 do
  begin
    if Random(100) < 50 then Result := Result + chr(RandomRange(48,57))
    else Result := Result + chr(RandomRange(65,90));
  end;
  Result := Result + '}';
end;

function genkey :string;
const
  Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var
  S: string;
  i, N: integer;
begin
  Randomize;
  S := '';
  for i := 1 to 30 do begin
    N := Random(Length(Chars)) + 1;
    S := S + Chars[N];
  end;
  result := S;
end;

function genkey2(c:integer) :string;
const
  Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var
  S: string;
  i, N: integer;
begin
  if c < 20 then c := 30;
  Randomize;
  S := '';
  for i := 1 to c do begin
    N := Random(Length(Chars)) + 1;
    S := S + Chars[N];
  end;
  result := S;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Lines.Add(GenID);
memo1.Lines.Add(genkey);
memo1.Lines.Add(genkey2(10));
end;

相关阅读 >>

Delphi app如何禁掉安卓锁屏

Delphi 技巧 以相同类名派生一个子类

Delphi添加任务栏右键菜单

Delphi一个抓屏的函数

Delphi 获取适合微信使用的当前日期,以int64表示,是当前时间和1970-01-01 00:00:00之间的秒差

Delphi paramstr 获取外部参数

java2op.exe,Delphi安卓原生桥接文件生成器

Delphi 生成日志记录单元

Delphi之如何快速开发原生activex控件

Delphi listbox防止添加重复

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



打赏

取消

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

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

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

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

评论

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