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 ();
    if (! itm.randomize() with { id < 10; })
    	$display ("Randomization failed");
    $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.