Constraint the number of ones in an unpacked array

If I have a packet that has:

class my_packet;
rand bit vector[31];

constraint c{....}

endclass

How do I write a constraint to limit the total number of ones for vector array to a certain range?

I tried to use vector.sum() > 8; vector.sum() <15; but the randomize() function fails to randomize for this.
Is this because sum() would only return a 1 bit answer to the constraint solver i.e 0 or 1?

In reply to shahid31091:

You are correct why it does not give the answer you want. Use

vector.sum() with (int'(item))