This posts lists small snippets from LRM 1800.
set membership - inside Link to heading
class b;
rand logic [2:0] x;
constraint x_c1 {x inside {1,2};}
constraint x_c2 {x inside {[0:3]};} //
constraint x_c2 {!(x inside {[0:3]});} // negation
endclass
Distribution Link to heading
class b;
rand logic [2:0] x;
constraint x_c1 {x dist {1:=1 ,2 := 2};} // 1,2
constraint x_c1 {x dist {[1:2]:=1 ,3 := 2};} // 1, 1, 2
constraint x_c1 {x dist {[1:2]/=1 ,3 := 2};} // 1/2,1/2,2
endclass
unique Link to heading
unique
says x and y shouldn’t take the same value.
class b;
rand logic [2:0] x;
rand logic [2:0] y;
constraint x_c1 {unique {x, y};}
endclass
implication Link to heading
This eliminates {1,0}, {1,1}, {1,3} .. {1,9}
class b;
rand logic [2:0] x;
rand logic [2:0] y;
constraint x_c1 { (x==1) -> (y==2); }
endclass
solver ordering Link to heading
class b;
rand logic [2:0] x;
rand logic [2:0] y;
constraint x_c1 { (x==1) -> (y==2); }
constraint x_c1 { solve x before y; }
endclass
soft constraint Link to heading
class b;
rand logic [2:0] x;
constraint x_c1 { soft x inside {[10:40]};}
endclass
inline contraint Link to heading
class b;
rand logic [2:0] x;
constraint x_c1 { soft x inside {[10:40]};}
endclass
b B =new;
B.randomize() with {x == 100};
Disable rand Link to heading
class b;
rand logic [2:0] x;
constraint x_c1 { soft x inside {[10:40]};}
endclass
b B =new;
// Disable variable
B.x.rand_mode(0);
// Disable for object
B.rand_mode(0);
// Disable
B.x_c1.contraint_mode(0);
inline random variable control Link to heading
class b;
rand logic [2:0] x,y;
constraint x_c1 { soft x inside {[10:40]};}
endclass
B.randomize(x); // y is state, x is random