生成随机代码

来源:互联网 发布:淘宝客可以关闭吗 编辑:程序博客网 时间:2024/06/15 14:23
 function RandomStr(majuscule:boolean;lowercase:boolean;number:boolean;digit:integer):string;
//大写字母,小写字母,数字,字符串的位数
var 
i: Byte; 
s: string;
begin
if majuscule then
s := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
else 
s := '';

if lowercase then
s := s + 'abcdefghijklmnopqrstuvwxyz';

if number then
s := s + '0123456789';
if s = '' then exit;

Result := '';
for i := 0 to digit-1 do //根据长度来循环 
begin
Randomize;//每次都初始化随机种子
Result := Result + s[Random(Length(s)-1)+1];
end;
end;
原创粉丝点击