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

Disable Randomization: Randomization Enabled by Default

SystemVerilog Randomization

Runnable example from the SystemVerilog Disable Randomization tutorial (Randomization Enabled by Default)

Open in IDE
testbench.sv
class Fruits;
  rand bit [3:0] var1;
  rand bit [1:0] var2;
endclass

module tb;
  initial begin
    Fruits f = new();
    $display ("Before randomization var1=%0d var2=%0d", f.var1, f.var2);

    // Turn off randomization for var2 this time
    f.var2.rand_mode (0);

    f.randomize();

    $display ("After randomization var1=%0d var2=%0d", f.var1, f.var2);
  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.