关于取随机数的奇怪问题
请建立一个Form,上面有两个Memo和一个Button。自定义函数如下:
function TForm1.GetRandomTableName: String;
var
iNum,iCyc,:Integer;
StrNum:String;
begin
iNum:=111111111;
Result:='';
StrNum:=IntToStr(iNum);
ShowMessage(StrNum);
For iCyc:=1 to Length(StrNum) do
Result:=Result+Chr(RandomInc(Ord(StrNum[iCyc])));
end;
function TForm1.RandomInc(iValue:Integer): Integer;
var
iRan:Integer;
begin
Repeat
Randomize;
iRan:=Random(8,74);
FormTest.Memo1.Lines.Add(IntToStr(iRan));
//ShowMessage(IntToStr(iRan));
Until (((iValue+iRan)>=65) and ((iValue+iRan)<=90)) or
(((iValue+iRan)>=97) and ((iValue+iRan)<=122));
Result:=(iValue+iRan);
end;
在Button的点击事件中激发第一个函数,然后看看两个Memo的内容;将第二个函数中的ShowMessage去掉注释,再执行一次,看看Memo有什么不同?
第一次没有ShowMessage的时候,每次调用第二个函数取到的值都是一样的,加上ShowMessage后就不一样了。哪位大虾能告诉我是什么原因?