Constraints question

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  

In reply to Verif Engg:
Yes there is a much better way. Use a unique constraint.

class example1;
 
  rand bit [6:0] par_groups; // why is this size different?
  rand bit[4:0] group[3];
 
  constraint group_c{unique {group};}

  constraint par_groups_c{par_groups inside {group};}
 
  function void post_randomize();
    $display("group = %p", group);
  endfunction  
 
endclass