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 8: Constrain a dynamic array such that it does not pick

SystemVerilog Interview Questions

Runnable example from the SystemVerilog Interview Questions Set 8 tutorial (Constrain a dynamic array such that it does not pick values from another array.)

Open in IDE
testbench.sv
module tb;
	bit [3:0] 	da [];
	bit [3:0] 	myq [$];

	initial begin
		repeat (10) myq.push_back($random);

		std::randomize (da) with {  da.size == 10;
									foreach (da[i]) { ! (da[i] inside {myq}); }
								 };
	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.