How to use easily method to randomize a variable with unique attributes inside a loop

I am writing below code to implement a simple solution with unique-randomize a variable but seems not working as expected.


        bit [7:0] my_addr;
        for (int i = 0; i < 10; i++) begin
            std::randomize(my_addr) with {unique {my_addr}; my_addr inside {[0:16]};};
        end

In reply to zz8318:

The unique constraint take a group of variables and assigns them unique values. Your unique has a single variable. According to the LRM, If the group of variables contains fewer than two members, the constraint shall have no effect.

If you want multiple unique values, you can give an array, such as my_addrs[10].

  bit [7:0] my_addrs[10];
  initial begin
    for (int i = 0; i < 10; i++) begin
      std::randomize(my_addrs) with {unique {my_addrs}; 
                                     foreach (my_addrs[i]) my_addrs[i] inside {[0:16]};};
      $display("%p", my_addrs);
    end
  end