Randomize dynamic array with unique values

In reply to bachan21:

class A;

  typedef bit [2:0] number_t;
  number_t recent_numbers[];
  
  function void post_randomize();
    recent_numbers = new[5];
    foreach (recent_numbers[i]) begin
      recent_numbers[i] = i;
    end
  endfunction : post_randomize

endclass : A


module top();

  A a = new();

  initial begin
    repeat(1) begin
    if(!a.randomize()) $display("Please look into randomization issue");
      $display("----->> recent_numbers = %p \n",a.recent_numbers);
    end
  end

endmodule : top