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.