HI All,
Sorry, I tried to use “code formatting”, but somehow I could not usse it, hence, I am just copy pasting as it is
To Generate a 3D vector [3][3][3] with values between -10 and 10.
array sum should be greater than 0.
.sum() method is not working here, could you please advice?
module p1;
class c1;
rand int addr[3][3][3];
constraint c1{
foreach (addr[a]){
foreach (addr[b]){
foreach (addr[c]){
addr[a][b][c]inside {[-10:10]};
}
}
}
addr.sum()>0;
//addr.sum() with (int'(item))>0;
}
function void post_randomize();
$display("elements %0p", addr);
endfunction
endclass
c1 obj;
initial begin
obj = new;
repeat (1)
obj.randomize();
end
endmodule
Output:
xmvlog: *E,WAATYP (testbench.sv,12|18): This type is illegal in this context [SystemVerilog].
addr.sum()>0;