Hi,
I have a 7 bit par_groups. Every time I randomize, I need to pick 3 groups that are unique and less than 32. Below is an example on how I did it.
Is there an better way to do it? This does not scale well. If I need to pick 15 unique groups from 32, this becomes a not so good solution.
Any feedback?
Thanks!
class example1;
rand bit [6:0] par_groups;
rand bit[4:0] group1;
rand bit[4:0] group2;
rand bit[4:0] group3;
constraint group1_c{group1 != group2;}
constraint group2_c{group2 != group3;}
constraint group3_c{group3 != group1;}
constraint par_groups_c{par_groups inside {group1, group2, group3};}
function void post_randomize();
$display("group1 = %d, group2 = %d, group3 = %d \n", group1, group2, group3);
endfunction
endclass
module test;
example1 ex;
function void run();
ex = new();
assert(ex.randomize());
$display("par_groups value is %d \n", ex.par_groups);
endfunction
initial run();
endmodule