Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Constraint Examples: Bidirectional Constraints

SystemVerilog Constraints

Runnable example from the SystemVerilog Constraint Examples tutorial (Bidirectional Constraints)

Open in IDE
testbench.sv
class myClass;
	rand bit [3:0] val;
	constraint  c1 { val > 3;
	                 val < 12; }
  
	constraint  c2  {val >= 10; }
endclass

module tb;
	initial begin
		for (int i = 0; i < 10; i++) begin
			myClass cls = new ();
			cls.randomize();
			$display ("itr=%0d typ=%0d", i, cls.val);
		end
	end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.