In reply to shaygueta:
Try following code. I guess it should work for you.
class C #(int unsigned WIDTH=16);
rand bit[31:0] IP_Table1[63:0];
rand bit[31:0] IP_Table2[63:0];
rand bit[31:0] Tx_IP_addresses[WIDTH-1:0];
rand protected bit _dummy_array[WIDTH-1:0];
constraint c_0 {_dummy_array.sum(item) with (int'(item == 1)) == WIDTH*8/10;} //WIDTH*0.8 = 80%
constraint c_1 {
foreach(_dummy_array[i]) {
(_dummy_array[i] == 1) -> Tx_IP_addresses[i] inside {IP_Table1, IP_Table2};
}}
constraint c_2 {
solve IP_Table1 before Tx_IP_addresses;
solve IP_Table2 before Tx_IP_addresses;
solve _dummy_array before IP_Table1;
solve _dummy_array before IP_Table2;
solve _dummy_array before Tx_IP_addresses;
}
virtual function void print();
$display("_dummy_array.sum()=%2d", _dummy_array.sum(item) with (int'(item == 1)));
$display("===============================================================");
foreach(_dummy_array[i]) begin
string aux = "";
foreach(IP_Table1[j]) begin
if(IP_Table1[j] == Tx_IP_addresses[i]) begin
aux = "IP_Table1"; break;
end
end
foreach(IP_Table2[j]) begin
if(IP_Table2[j] == Tx_IP_addresses[i]) begin
aux = "IP_Table2"; break;
end
end
$display("_dummy_array =%2d | %9s | Tx_IP_addresses =%11d", _dummy_array[i], aux, Tx_IP_addresses[i]);
end
endfunction : print
endclass
module top();
C#(.WIDTH(200)) c;
initial begin
c = new;
rnd:assert(c.randomize());
c.print();
end
endmodule : top