您的位置:程序门 -> delphi -> 语言基础/算法/系统设计



探讨delphi生成短数字唯一性id问题,无分


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


探讨delphi生成短数字唯一性id问题,无分
发表于:2008-01-21 16:31:31 楼主
delphi(pascal) code
function getuid:string; var guid: tguid; uid : string; i:integer; total:integer; begin if cocreateguid(guid) = s_ok then uid := guidtostring(guid); uid:=stringreplace(uid, '-','',[rfreplaceall]); uid:=stringreplace(uid, '{','',[rfreplaceall]); uid:=stringreplace(uid, '}','',[rfreplaceall]); total := 0; for i:=1 to length(uid) do begin total := total + ord(uid[i])*i; end; result := inttostr(total); end;


我用这种方法大概生成是5位的数字id,自认为不会有重复的情况,不知各位大大以为何?
发表于:2008-01-21 16:41:541楼 得分:0
楼主自己有测试过吗?再不谈效率,测试看在多少之内就有可能会重复。
发表于:2008-01-21 22:03:152楼 得分:0
重复几率很大,你这个和随机生成没太大区别


快速检索

最新资讯