To all:这是一个数据库程序,设置标志我觉得不可行,设置标志还是避免不了比较;
To yangkunjie(杨七郎(dephi--c#)):我觉得你说的直接从中抽走的办法比较好,这样就不必去比较了,非常感谢!

解决方案 »

  1.   

    To chiphead(满脑袋芯片和程序的人):你的办法不行,每五个就必有一个被抽中,但事实上前100个可能都没有一个抽中,你说呢?
      

  2.   

    我的方法我试过10000个数的数组中找不重复得数,竟然没有超过1秒钟
    一般的方法都是2个for循环、而我的程序只要1个for循环,速度大大的提高拉
      

  3.   

    var
      Dest: array[1..20000] of Integer;
      Source: array[1..100000] of Integer;
      I, J, T: Integer;
      MaxIndex: Integer;
    begin
      Randomize;
      MaxIndex := 100000;
      for I := 1 to 20000 do begin
        J := Random(MaxIndex) + 1;
        T := Source[J];
        Source[J] := Source[MaxIndex];
        Source[MaxIndex] := T;
        Dest[I] := T;
        Dec(MaxIndex);
      end;
    end;
      

  4.   

    请你搜索kingron发的帖子又一个例子
      

  5.   

    To zSWANg(伴水)(* pascal→c *):我一查到了Kingron的帖子,对这个问题明白不少,谢谢大家,有好的建议请继续,明天结帖!
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      x:array[0..999999] of boolean;
      y:array[0..19999] of integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var i,z:integer;
    begin
      i:=0;
      while i<20000 do begin
        z:=random(999999);
        if not x[z] then begin
          y[i]:=z;
          i:=i+1;    end;
      end;
      showmessage('OK!')end;procedure TForm1.Button2Click(Sender: TObject);
    var i:integer;
    begin
      memo1.Clear;
      for i:=0 to 19999 do memo1.Lines.Add(inttostr(y[i]));
    end;end.
     半秒算出来!
      

  7.   

    to scripting(scripting)
    请问你这是什么意思
    if not x[z] then begin  
          y[i]:=z;
          i:=i+1;
        end;别人要的是在100000个数中找出一个都不相同的20000个数
    放到另一个数组中
    你的 not x[z]要是z随机的时候重复了怎么办...我写一秒不到是正确的.
    你的答案是错误的.