用Randomize可以避免随机数重复 或者你可以用Listbox的indexof属性来判断是否重复 procedure TForm1.Button1Click(Sender: TObject); var t:string; begin while ListBox1.Items.Count <7 do begin t:= IntToStr(Random(30)); if ListBox1.Items.IndexOf(t)<0 then ListBox1.Items.Add(t); end; end;
或者你可以用Listbox的indexof属性来判断是否重复
procedure TForm1.Button1Click(Sender: TObject);
var t:string;
begin
while ListBox1.Items.Count <7 do
begin
t:= IntToStr(Random(30));
if ListBox1.Items.IndexOf(t)<0 then ListBox1.Items.Add(t);
end;
end;
hellolongbin(一个人[散分贴一律征收20%灌水税]) 太认真了,用Randomize的方法,生成的数都奇大无比,重复的可能性几乎为0,完全是小概率事件——小概率事件是不可能发生的。楼主如果是要写彩票号码生成程序,括号里的30才是必需的——30是不是小了一点?
也别搞这种哗众取宠的把戏