Constraint dynamic array

I have below two programs which don’t work as I expect it to work. Not sure, what is wrong!
I want the dynamic array with size 10 and all unique elements and elements should be greater than 10.

class class_name;
  rand bit [3:0] arr[];

  function pre_randomize();
    //arr.size() = 10;      //This did not work
    arr = new[10];
  endfunction : pre_randomize

  constraint ct_arr_u {
    unique{arr};
  }
  constraint ct_arr_each {
    foreach(arr[i]) arr[i] > 10;
  }
endclass : class_name

module module_name();
  class_name cn_inst = new();

  initial begin
    cn_inst.randomize();  
    foreach (cn_inst.arr[i]) begin
      $display("Array element %d value %d",i,cn_inst.arr[i]);
    end
  end
endmodule : module_name

ERROR: it says constraints in the class conflicts
OUTPUT of the above code,
Array element 0 value 0
Array element 1 value 0
Array element 2 value 0
Array element 3 value 0
Array element 4 value 0
Array element 5 value 0
Array element 6 value 0
Array element 7 value 0
Array element 8 value 0
Array element 9 value 0

class class_name;
  rand bit [3:0] arr[];

  constraint ct_arr {
    arr.size() == 10;
  }
  constraint ct_arr_u {
    unique{arr};
  }
  constraint ct_arr_each {
    foreach(arr[i]) arr[i] > 10;
  }
endclass : class_name

module module_name();
  class_name cn_inst = new();

  initial begin
    cn_inst.randomize();  
    foreach (cn_inst.arr[i]) begin
      $display("Array element %d value %d",i,cn_inst.arr[i]);
    end
  end
endmodule : module_name

ERROR: It says constraints conflicts.

Thank you.

In reply to megamind:

The main issue I see is how can you expect out an array of 4 bits elements have them all unique and greater than 10, when there are only 5 combinations (11, 12, 13, 14, 15) meeting that criteria, also as you stated in your code the size method cannot be assigned in the pre randomize method, you can set the size using new, or in a constraint x.size()== 10.

HTH,

-R

In reply to megamind:

The size method is a query function that returns a value—you can’t make an assignment to it. If you put the size method as part of a constraint expression, the constraint solver will change the size of the array to make the expression evaluate true.

You should always test return value of randomize. It returns true if the solver was able to find values that satisfy the constraints. It returns false if it was unable to satisfy the constraints and leaves the random variables on modified, which in this case is all 0’s.

The solver is unable to satisfy the constraints because they are only five values greater than 10 and you’ve asked for 10 unique values.

In reply to dave_59:

Thank you rgarcia07 and Dave, problem is resolved and well understood now. Thank you.