注意:是整数数组啊
请各位帮忙!!!

解决方案 »

  1.   

    你先用randem产生一个实数数组 再quick_sort一下 排序的序号就是你要的无重复的随机~整数~数组
      

  2.   

    random()函数生成随即数,详细的参看delphi帮助。
    ^_^
      

  3.   

    取不同随机数的通用函数
    type
       n=array of integer;
    //Max-2>=Number
    function G(Max:integer;Const Number:integer):n;
    var i,j:integer;
          Num:n;
          Curr:integer;
          Mark:boolean;
      begin
        Memo1.clear;
        //取13个随机数
        for i:=0 to Number do
        begin
          while true do
          begin
            Mark:=False;
            //取1-14之间的随机数
            Curr:=random(Max);
            //0不取
            while curr=0 do
               Curr:=Random(Max);
            //查找是否有相等的
            for j:=0 to High(Num) do
               if Curr=Num[j] then
               begin
                  Mark:=true;
                  break;
               end;
            if not Mark then break;
          end;
          SetLength(Num,i+1);
          Num[i]:=Curr;
        end;
        result:=Num;
      end;
      

  4.   

    你的大O为N*(N-1)/2 我的为N+N*logN
      

  5.   

    to : IwantFlay(我很爱她!!!!!!!!!!)
        哥们儿,要是产生一百个,很慢的,不知道楼主要要多少到多少之间的随机数啊?
      

  6.   

    var
      array1 : array[1..100] of integer;
      i, j, temp : integer;
      lg : boolean;
    begin
      i := 1;
      lg := true;
      Randomize;
      while i <= 100 do
      begin
        //产生1到10000之间的随机数,想产生1到100的,把10000改成100就行了
        temp := round(random(10000))+1;
        for j := 1 to i do
        begin
          if array1[j] = temp then
          begin
            lg := false;
            break;
          end;
        end;
        if lg then
        begin
          array1[i] := temp;
          i := i + 1;
        end;  end;
    end;
    不过这样非常慢,,不可能用到程序里
      

  7.   

    const ARR_LOW=1;ARR_HIGH=80;
    var Arr:array[ARR_LOW..ARR_HIGH] of integer;
      pos1,pos2:integer;i:integer;
    begin
      //初始化随机数序列
      Randomize;
      //用有序的数字初始化数组,以保证绝对没有重复
      for i:=ARR_LOW to ARR_HIGH do
        Arr[i]:=i;
      //打乱数组里面的顺序(也就是随即交换)
      for i:=ARR_LOW to ARR_HIGH do//也可以把这里的ARR_HIGH改为其他数字,但是推荐大于等于ARR_HIGH的数字,太大了浪费时间,太小了生成的数列不太"随机" :P
      begin
       //随机交换两个元素
       pos1:=Round(Random(ARR_HIGH))+ARR_LOW;
       pos2:=Round(Random(ARR_HIGH))+ARR_LOW;
       Arr[pos1]:=Arr[pos1] xor Arr[pos2];
       Arr[pos2]:=Arr[pos1] xor Arr[pos2];
       Arr[pos1]:=Arr[pos1] xor Arr[pos2];
      end; 
     ......................................
      //ok,这个代码生成的随机数列绝对是没有重复的啦
    end;
      

  8.   

    to:Eastunfail(恶鱼杀手)
    你你这样的算法可以限制最大的随机数吗??
      

  9.   

    修改 const ARR_LOW=1;ARR_HIGH=80;。或者你干脆封装成一个函数算了
      

  10.   

    to:Eastunfail(恶鱼杀手)
    你能帮我解释一下你的这个算法吗?
      

  11.   

    我的更快,只用一个while,用集合,很简单:var randomnum:array[1..100] of integer;
        numset:set of 1..81;
        n,m:integer;
    begin
      randomize;
      n:=1;
      numset:=[];
      while n<=80 do
        begin
        m:=random(80);
        if not(m in numset) then
          begin
          randomnum[n]:=m;
          n:=n+1;
          numset:=numset+[m];
          end;
        end;
    end;
    randomnum就是随机整数集合,绝对无重复
      

  12.   

    集合有数量限制。呵呵。我的算法很EAZY,先给数组的每个元素附上从0开始依次递增的数字.然后将那个数组的元素打乱.就OK了.
      

  13.   

    Delphi帮助里面的:
    The range of a set type is the power set of a specific ordinal type, called the base type; that is, the possible values of the set type are all the subsets of the base type, including the empty set. The base type can have no more than 256 possible values, and their ordinalities must fall between 0 and 255. Any construction of the form
      

  14.   

    to: Eastunfail(恶鱼杀手) 
    假如我要从0-400中间产生80个随机数呢?
    你的还行不?
      

  15.   

    可以,他的数量限制只是限制在产生随机数的个数上,不是范围,
    The base type can have no more than 256 possible values意思是不能超过256个值而不是指不能超过256。
    你只用把m:=random(80);改成m:=random(400);就可以从0-400中间产生80个随机数。
    不信你试一试。
      

  16.   

    我看如果真要产生80个随机数,楼主还是选   boywu(Boywu) 的比较好。
      

  17.   

    额~~~~~~我的算法有一个缺点:只能够产生ARR_HIGH-ARR_LOW+1个范围在[ARR_HIGH,ARR_LOW]的随机数。但是速度快,绝对不重复