RSS订阅 | 匿名投稿
您的位置:网站首页 > 单元 > 正文

delphi 随机函数单元uRandomUtils

作者:admin 来源: 日期:2018/3/15 15:44:46 人气: 标签:

unit uRandomUtils; //晓不得2013 QQ:26562729

interface

uses system.math, system.SysUtils;

function GetRandomCharStr(ADig: integer): string;
function GetRandomNumStr(ADig: integer): string; overload;
function GetRandomNumStr(AStart, AEnd: integer): string; overload;
function GetRandomHanziStr(ADig: integer): string;

implementation

type
  TGetRandomChar = reference to function: Char;

const
  HanZi = '平丽强勇军梅建化国中天莉尚丰田开杰锦思小晓伦春满淋叶风亚唯赵';

function GetRandomString(ADig: integer; AGetRadomChar: TGetRandomChar): string; overload;
var
  i: integer;
begin
  Result := '';
  if ADig < 1 then exit;
  for i := 1 to ADig do
  begin
    Randomize;
    Result := Result + AGetRadomChar;
  end;
end;

function GetRandomCharStr(ADig: integer): string;
var
  AChar: TGetRandomChar;
begin
  AChar := function: Char
    begin
      Result := Char(RandomRange(65 + 32, 91 + 32));
    end;
  Result := GetRandomString(ADig, AChar);
end;

function GetRandomNumStr(ADig: integer): string;
var
  AChar: TGetRandomChar;
begin
  AChar := function: Char
    begin
      Result := inttostr(RandomRange(0, 10))[1];
    end;
  Result := GetRandomString(ADig, AChar);
end;

function GetRandomNumStr(AStart, AEnd: integer): string; overload;
begin
  Result := IntToStr(RandomRange(AStart, AEnd + 1));
end;

function GetRandomHanziStr(ADig: integer): string;
var
  AChar: TGetRandomChar;
  nHanzi: integer;
begin
  nHanzi := length(HanZi) + 1;
  if nHanzi <= 1 then exit('');
  AChar := function: Char
    begin
      Result := HanZi[RandomRange(1, nHanzi)];
    end;
  Result := GetRandomString(ADig, AChar);
end;

end.


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料