Complete the code to declare a random variable in SystemVerilog.
rand bit [1];The keyword rand declares a random variable named data.
Complete the code to generate a random value for the variable.
assert([1].randomize());The randomize() method is called on the random variable data to generate a new random value.
Fix the error in the code to constrain the random variable to values less than 10.
constraint data_limit { [1] < 10; }The constraint must refer to the random variable data to limit its values.
Fill both blanks to declare a class with a random variable and a constraint.
class RandomGen; rand bit [1]; constraint [2]_limit { [1] < 16; } endclass
The random variable is named value, and the constraint is named value_limit to match.
Fill all three blanks to create a testbench that randomizes a variable and displays its value.
module testbench; [1] rand_var; initial begin rand_var = new(); if (rand_var.[2]()) begin $display("Random value: %0d", rand_var.[3]); end end endmodule
The module declares an instance of class RandomGen, calls randomize() to generate a value, and displays the value variable.
