*In reply to dave_59:*

Hi Dave,

Please explain the behaviour for the array size of three. And why the constraint is not conflicting ?? And How it is generating a random output for a size of three ??

Please find the below snippet.

```
module array_size();
class A;
rand bit [7:0] a[$];
int k;
constraint SIZE_SUM {
a.size == 3 && a.sum == 50;
}
function void post_randomize();
foreach(a[i])
k = k + a[i];
$display("a size is %0d, METHOD :: sum of a array is %0d, CALC :: k is %0d, array values are %0p",a.size,a.sum,k,a);
if(k == a.sum)
$display("PASS");
k = 0;
endfunction
endclass : A
initial
begin
repeat(100)
begin
A b =new();
b.randomize();
end
end
endmodule
```

Output :-

output : for size 3

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h9, 'h25, 'h4}

PASS

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 562, array values are '{'hbb, 'hb4, 'hc3}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 306, array values are '{'h29, 'h4c, 'hbd}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 306, array values are '{'ha, 'hfd, 'h2b}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 562, array values are '{'hed, 'h84, 'hc1}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 306, array values are '{'h15, 'hff, 'h1e}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 306, array values are '{'hc3, 'h64, 'hb}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 562, array values are '{'h93, 'hfc, 'ha3}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 562, array values are '{'he8, 'h96, 'hb4}

a size is 3, METHOD :: sum of a array is 50, CALC :: k is 562, array values are '{'hba, 'hf4, 'h84}

output for size 5

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h0, 'h0, 'h0, 'h9, 'h29}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h1, 'h0, 'h1, 'h6, 'h2a}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h15, 'h0, 'h4, 'h0, 'h19}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h0, 'h0, 'h0, 'h31, 'h1}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h0, 'h2, 'hc, 'h0, 'h24}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h1f, 'h2, 'h9, 'h0, 'h8}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'ha, 'h1d, 'h0, 'h0, 'hb}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h27, 'h0, 'h0, 'h9, 'h2}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h0, 'h0, 'h0, 'h27, 'hb}

PASS

a size is 5, METHOD :: sum of a array is 50, CALC :: k is 50, array values are '{'h1e, 'h1, 'h0, 'h13, 'h0}

PASS