Hi Everyone,
I want to find out all possible combinations of 3 variables which sum up to 20. I used a queue to get the unique values, it works well for 2 variables. But for 3 variables it misses out some combinations.
if a=2,b=2,c=16; is present a=2,b=3,c=15 will be missed, as it is already present in the queue.
Is there a way to store the combination of a,b,c and then check it is covering all values?
class rand_val;
rand int a,b,c;
int a_val[$];
int b_val[$];
int c_val[$];
int X=20;
constraint val_c {a+b+c == X;a >= 2; a <= 14; b >= 2; b <= 14; c >= 2; c <= 14;}
constraint uniq_c{(!(a inside {a_val}) && !(b inside {b_val}) && !(c inside {c_val}));}
function void print();
$display("The values are %d, %d, %d", a,b,c);
endfunction
function void post_randomize();
a_val.push_back(a);
b_val.push_back(b);
c_val.push_back(c);
endfunction
endclass
module top;
initial
begin
rand_val r;
r=new();
forever begin
if(!r.randomize()) begin
$display("Unique A is %p", r.a_val);
$display("Unique B is %p", r.b_val);
$display("Unique C is %p", r.c_val);
break;
end
end
$finish;
end
endmodule