In reply to dave_59:
Hi Dave, I tried below code and randomized 10 times. I am not able to understand the output here. what the a.sum value returning?
class A;
rand bit [4:0] a [3][3];
constraint c1 {
// a.sum() == 15; // illegal
// a.sum() with (item.sum) == 15;
}
endclass
module top;
A h = new;
initial begin
repeat(10) begin
assert (h.randomize);
// $display(h.a.sum()); // illegal
$display("a = %p", h.a);
$display(h.a.sum() with (item.sum));
end
end
endmodule
below is the oupout
a = '{'{'h3, 'hf, 'h11}, '{'ha, 'h4, 'h13}, '{'h2, 'h9, 'h1e}}
13
a = '{'{'h16, 'h17, 'h16}, '{'h11, 'h3, 'h1d}, '{'h1b, 'h1e, 'h18}}
5
a = '{'{'h1, 'h1e, 'h13}, '{'hc, 'h19, 'h12}, '{'hc, 'h14, 'hb}}
20
a = '{'{'h9, 'hf, 'h15}, '{'h13, 'h17, 'ha}, '{'h1, 'h4, 'h9}}
15
a = '{'{'hd, 'h1f, 'h18}, '{'h7, 'h18, 'h15}, '{'h1f, 'hc, 'hb}}
14
a = '{'{'h7, 'h8, 'h1}, '{'h1, 'hc, 'h10}, '{'h4, 'h3, 'h1b}}
15
a = '{'{'h10, 'h1, 'h7}, '{'h12, 'h7, 'h1c}, '{'h4, 'h17, 'h0}}
8
a = '{'{'h12, 'h15, 'h1a}, '{'h2, 'h11, 'h7}, '{'hb, 'h1b, 'h1a}}
27
a = '{'{'h1d, 'hd, 'h1f}, '{'h9, 'h8, 'he}, '{'h11, 'h1, 'h1}}
27
a = '{'{'h1a, 'h16, 'h18}, '{'h7, 'h17, 'h18}, '{'h1f, 'h7, 'h1d}}
1