Constraint to generate an array of random numbers where a certain value is repeated fixed number of times

In reply to sasi_8985:

Yes the constraint in itself will work. There is No need for calling function from constraint.

here’s how the constraint is unrolled ::

(1) Since we have a.sum() , addtition operator ‘+’ is used

(2) item refers to element of a i.e a[0] , a[1] , a[2] … a[9]

So  the  resultant  expression  is  :: 

int’( a[0] == 5 ) + int’( a[1] == 5 ) + … + int’( a[9] == 5 ) == 5 ;

 Result  of  comparison  operator '=='  is  either 1'b0 / 1'b1 . 

The ONLY way randomization is successful is when there would be ( any ) 5 elements
in ‘a’ having element value as 5 .

Refer LRM 18.5.8.2 for more info .