In reply to Harshad:
The function prime(arg) is returning the argument passed into it if the argument is a prime number, otherwise it returns 2. This assumes the limit is going to be 2 or greater. Then post_randomize() eliminates all the duplicate 2's.
This might be a clearer way to write the class
class prime_number;
int limit;
rand int a[];
constraint abc {a.size==limit; limit > 1; }
constraint cba { foreach(a[i])
if (prime(i))
a[i] == i;
else
a[i] == 2;
}
function bit prime( int g);
if(g <= 1) return 0; // not a prime
for(int i=2;i<g;i++)
if(g%i==0)
return 0; // not a prime
return 1; // is a prime
endfunction
function void post_randomize();
a=a.unique; // gert rid of duplicate 2's
endfunction
endclass