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 6: Randomly generate 8, 16, 32, 64 with equal probabilit

SystemVerilog Interview Questions

Runnable example from the SystemVerilog Interview Questions Set 6 tutorial (Randomly generate 8, 16, 32, 64 with equal probability using SystemVerilog constructs.)

Open in IDE
testbench.sv
module tb;
	initial begin
		bit [31:0] result;
		
		result = 1 << $urandom_range(3, 6);
	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.