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

randcase: Weighted Random Branch Selection

SystemVerilog Randomization

Runnable example from the SystemVerilog randcase tutorial (Weighted Random Branch Selection)

Open in IDE
testbench.sv
module tb;
	initial begin
      for (int i = 0; i < 10; i++)
      	randcase
        	0 	: 	$display ("Wt 0");
      		5 	: 	$display ("Wt 5");
      		3 	: 	$display ("Wt 3");
      	endcase
    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.