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

After Using Rand_mode()

SystemVerilog Randomization

f.rand_mode(0) called on the object turns off randomization for all of its rand variables at once.

Open in IDE
testbench.sv
// Create a class that contains random variables
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);
    
    // Turns off randomization for all variables
    f.rand_mode (0);    
    
    if (! f.var1.rand_mode())
      if (! f.var2.rand_mode())
        $display ("Randomization of all variables disabled");
    
    f.randomize();
    
    $display ("After randomization var1=%0d var2=%0d", f.var1, f.var2);
  end
endmodule
design.sv
// Code your design here
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.