In reply to brab:
bit [9:0] ready_boxes;
bit [9:0] weight_box[$] ={10,5,5,7,3,5,5,10,10,50};
rand int chosen_box[]; // Changed to Unpacked Array !!
rand int val ;
constraint SIZE { chosen_box.size() == weight_box.size() ; }
constraint DIST { foreach( ready_boxes[i] )
{
if ( ready_boxes[i] == 1 )
{
chosen_box[i] dist { i := weight_box[i] } ;
}
}
}
constraint VALUE { val inside { chosen_box } ; }
Via VALUE constraint would chose any value from chosen_box with equal probability .
Each element of chosen_box would be selected a value with appropriate weight
Not 100% sure if this satisfies the weight distribution too . Please correct me if wrong