class example;
rand bit[5:0] arr[$];
rand bit[5:0] arr_unique[$];
rand bit [5:0] arr1[$],arr2[$],arr3[$];
constraint queue_sz{
arr.size() == 15;
//arr_unique[$] == arr.unique();
arr1.size()+arr2.size()+arr3.size() == arr.unique().size();
15>arr1.size()>0;
15>arr2.size()>0;
15>arr3.size()>0;
}
constraint subdivision{
foreach(arr1[i]){
arr1[i] == arr.pop_front();
}
foreach(arr2[i]){
arr2[i] == arr.pop_front();
}
foreach(arr3[i]){
arr3[i] == arr.pop_front();
}
}
function void print();
$display("value of array is %p",arr);
$display("value of array_un is %p",arr1.size());
$display("value of array1 is %p",arr1);
$display("value of array2 is %p",arr2);
$display("value of array3 is %p",arr3);
endfunction
endclass
initial begin
example ex;
ex = new();
repeat(2) begin
ex.randomize();
ex.print();
end
$finish;
end
endmodule
Output:
# value of array is '{56, 57, 4, 36, 26, 54, 4, 53, 26, 35, 10, 16, 36, 24, 17}
# value of array_un is 6
# value of array1 is '{4, 4, 4, 4, 4, 4}
# value of array2 is '{57, 57, 57, 57}
# value of array3 is '{56, 56}
i tried above code, but not working, can anyone help ?
15>arr1.size()>0; is not what you should be writing to constrain a value in a range. It is actually ( 15 > arr1.size() ) > 0 which only works if minimum in the range is 0. That’s because the result of ( 15 > arr1.size() ) can only be 1’b1 (true) or 1’b0 (false). You should use the inside operator.