In reply to Shashank Gurijala:
class cls; rand bit [29:0] a, b, c; constraint cons1 {$countbits(a, 1) == 10;} endclass