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

Interview Questions Set 7: Write SV code to wait for a random delay in range 100

SystemVerilog Interview Questions

Runnable example from the SystemVerilog Interview Questions Set 7 tutorial (Write SV code to wait for a random delay in range 100 to 500 ns.)

Open in IDE
testbench.sv
`timescale 1ns/1ps

module tb;
	initial begin
		int delay;

		std::randomize(delay) with { delay inside {[100:500]}; };
		#(delay) $display("Statement printed after %0d delay", delay);

		// This is also good enough, although there's no variable to print actual randomized delay
		#($urandom_range(100, 500)) $display("Some delay between 100 to 500");
	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.