I am trying to generate an array of prime numbers using constraint. But the code is printing an empty array. Where am I wrong?
class abc;
rand bit [4:0] a;
int i;
constraint a0{a.size() == 100;}
constraint a1{ foreach (a[i])
a[i] == prime(a[i]);}
function integer prime (int val);
if (val <=1) return 0;
for(i=2;i<val/2;i++)begin
if(val%i==0)
break;end
return val;
endfunction
endclass
module xyz;
initial begin
abc m_h;
m_h = new();
m_h.randomize();
$display(“\n Array of Prime with %0p”, m_h.a);
end
endmodule
Output is :
A is '{}