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

Inline Constraints: Basic Inline Constraint

SystemVerilog Constraints

Runnable example from the SystemVerilog Inline Constraints tutorial (Basic Inline Constraint)

Open in IDE
testbench.sv
class Item;
  rand bit [7:0] id;
  
  constraint c_id { id < 25; }
  
endclass

module tb;
  
  initial begin
    Item itm = new ();
    itm.randomize() with { id == 10; }; 		// In-line constraint using with construct
    $display ("Item Id = %0d", itm.id);
  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.