Hi,
For a N bit vector I want to generate all combinations with M bits set.
module nmbits;
parameter N = 4;
parameter M = 2;
class temp;
rand bit [N-1:0] val;
bit [N-1: 0] val_q[$];
constraint val_c {
$countones(val) == 2;
unique {val, val_q};
}
function void post_randomize();
val_q.push_back(val);
endfunction: post_randomize
function gen_val();
for (int i=0; i<2**N; i++) begin
assert(this.randomize); $display("%d",val);
end
foreach(val_q[j]) $display("val_q[%0d]: %b", j, val_q[j]);
endfunction: gen_val
endclass: temp
initial begin
temp mn = new;
assert(mn.randomize);
mn.gen_val();
end
endmodule: nmbits
Is there a better way of implementing this?
Thanks