Complex randomization constraint

In reply to chenm:

In reply to chenm:

A dist constraint is a statistical distribution and not a hard constraint. You can use the sum reduction method to constrain that an output appears at most once.

module top;
  class test;
    // Test fields
    rand bit [8*4-1:0]       ipe_stream_src_sel;
    rand bit [3:0]      src_sel[8];
    const bit [3:0] one_hot[] = {0,1,2,4,8};
 
    constraint src_sel_c {
      foreach(src_sel[i]) {
        src_sel[i] inside {one_hot};
        ipe_stream_src_sel[i+:4] == src_sel[i]; // use instead of post_randomize
      }
      foreach(one_hot[sel])
        sel != 0 -> src_sel.sum() with ( int'(item==one_hot[sel]) ) <= 1;
    }
  endclass : test
   
  test t = new;
  initial repeat (5) begin
    assert(t.randomize);
    $displayh("%p",t);
  end
endmodule