Complex constraints

There is a rand variable in a class.we have to write a constraint that the no. of times this variable gets randomized, it should sum equal to 500.
For eg.
class A;
rand a;
endclass

now suppose if this variable gets randomized 5 times the sum of all random generated values should be equal to 500.how to write constraint for it.

Although it is easy to write constraints that involve previous sets of randomized values, this kind of constraint is very difficult produce using separate calls to randomize.

A better way would be to have a single call to randomize() with a constraint that generate N elements in an array where the sum of the elements equals a particular value you want. Then pick each element out of the array in order as you need them.