Is there a way to populate a queue using elements from another random queue in a constraint-based way? For example,
class some_class;
rand bit [7:0] choices [$];
rand bit [7:0] chosen [$];
int num_choices = 20;
int num_chosen = 5;
function new();
endfunction
constraint choices_size_c { choices.size() == num_choices; }
constraint chosen_c {
chosen.size() == num_chosen;
foreach (chosen[i]) {
// check chosen[i] exists somewhere within choices
}
}
endclass
The idea is we have a number of valid choices that, for example, get programmed somewhere. Then we choose 5 of those valid choices for testing. Can this be done with constraints, or do I need to do this manually post-randomization?