Probability on Constraint in SystemVerilog

Hi
I have multiple random constraints in a class. Can I have another constraint that assign weights to constraints?
For example how can have constraint totall to probability of A will become 0.3, B 0.3 and C will 0.4?
constraint A{
};
constraint B{
};
constraint C{
}:
constraint totall{
};

In reply to Moein75:

rand enum {pA, pB, pC} select;
constraint A{
  pA -> {your_A_constraint};
}
constraint B{
  pB -> {your_B_constraint};
}
constraint C{
  pC -> {your_C_constraint};
}
constraint totall{
  dist select {pA:=30, pB:=30, pC:=40};
}

In reply to dave_59:

Can we have after → foreach?
like this:

constraint B{
        s2 -> (
            foreach(len[j])
            begin
                if (len[j])
                    begin
                    e1[j:j+6]==7'b0011011;
                    end
            end
        );
    }

In reply to Moein75:

You can have foreach, but not the begin/end constructs. Constraints are not procedural code even though they share some syntax. You should write this as


constraint B { s2 ->  foreach(len[j]) 
                          len[j] -> e1[j:j+6]==7'b0011011 ; }

Thanks,
Do you know what is the wrong with this code?

class TransactionIn ;
    

//-------------------The random variables
 
 
    rand int rl[256];

    

//--------------------------------------
     
	constraint num_FAS {
        foreach(rl[i])        
			rl[i] inside {[0:1]};
        foreach(rl[i])
        if(i<220) 
		  if (rl[i])
                 rl[i+1 +: 3] == '{1,1,1};
        rl[254]==0;

        
        rl.sum() < 32;
                      }
endclass 

module example2;
TransactionIn a;
    initial begin
      
        a = new();
        assert(a.randomize());
        $display(a.rl);
 
       

    end
endmodule

** Error: example2.sv(108): (vopt-2936) Illegal non-integral expression in random constraint.

** Error: (vopt-2064) Compiler back-end code generation process terminated with code 2.

Error loading design

In reply to Moein75:

Hi, I guess it’s happening because the range is not constant inside that constraint. Again I am not sure. It’s my assumption. I tried to change a few things and it’s working now properly. Please go through it.


class TransactionIn ;
  
//-------------------The random variables
    rand int rl[256];
//--------------------------------------
  
	constraint num_FAS {
      
        foreach(rl[i])        
			rl[i] inside {[0:1]};
      
        foreach(rl[i])
          i<220 -> rl[i] -> rl[i+1]==1 && rl[i+2]==1 &&rl[i+3]==1; 
		  
        rl[254]==0;
      
        rl.sum() < 32;
                      }
endclass 

module example2;
TransactionIn a;
    initial begin
        a = new();
        assert(a.randomize());
      $display("%0p",a.rl);
    end
endmodule

In reply to Moein75:

Your problem is your expression
rl[i+1 +: 3] == '{1,1,1};
is a comparison of two arrays and constraints can only be expressions of integral expressions. You need to unroll this into a comparison of 3 array elements.