Program to generate prime numbers in from an array using constraint

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 '{}

In reply to criz:

I probably will not assign the prime num to array in constraint structure.
I will use “function void post_randomize” to run the prime function then assign it.
I use my own prime number generator.
I hope this will help you.

In reply to criz:

See https://verificationacademy.com/forums/systemverilog/prime-numbers-constraint

as well as searching this forum for other questions about generating prime numbers with constraints