In reply to aaaaaa:
class fs_array;
rand bit[4:0] array1[];
constraint d_size{array1.size==50;array1.sum() == 17;}
constraint c3{
array1.sum(item)with(item >0 &int'(item%4 ==0))==1;}
function void display();
$display("array1 = %p",array1);
endfunction
endclass
module tb();
fs_array fs_h;
initial
begin
fs_h =new();
if(fs_h.randomize())
fs_h.display();
end
endmodule
Hope my understanding of your question is correct
Output :-
size = 5 O/P = array1 = '{4, 5, 0, 6, 2}
size=10 O/P=array1 = '{0, 7, 0, 0, 1, 0, 0, 4, 2, 3}
size 50 O/P=array1 = '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 2, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}