用了一个线程来产生n组随机数
每组数字是一组彩票号
可是运行的时候总是会连续两组或三组号码完全一样我也用了randomize
好象没用

解决方案 »

  1.   

    给你个函数,产生N个从MINNO到MAXNO中选SELECTNO个号码的函数;
    function Roule1L(n,maxno,minno,selectno:byte):String;
    var
       selectnoarr:array of integer;
       tmp,i,j:byte;
       tmpstr,tmpstr1:string;
    begin
      SetLength(selectnoarr,maxno-minno+1);
      for i:=minno to maxno do
        selectnoarr[i-minno]:=i;
      Randomize;
      for i:=1 to n do
      begin
        for j:=1 to selectno do
        begin
          tmp:=RandomFrom(selectnoarr);
          while (Pos(RightStr(Format('0%d',[tmp]),2),tmpstr)>0) do
          begin
            tmp:=RandomFrom(selectnoarr);
          end;
          tmpstr:=RightStr(Format('0%d',[tmp]),2)+tmpstr;
        end;
        tmpstr1:=tmpstr+','+tmpstr1;
        tmpstr:='';
      end;
      result:=Copy(tmpstr1,1,Length(tmpstr1)-1);
    end;
      

  2.   

    注意:在循环中不可以调用DELPHI的随机数初始化函数,如果你把产生随机数的程序写成一个函数,那么,初始化函数也不能包含在你的这个函数里。否则,如果你在循环中调用该函数,也会有重复的现象。
    解决的办法是:在主程序(主窗体)开始,调用初始化函数。然后在需要的地方调用产生随机数的函数。