Randomization allows for the creation of random stimulus, which is critical for thorough testing and coverage of all possible scenarios.
Variables can be declared as random using the rand and randc keywords.
rand: generates random values with repetition.
randc: generates random values without repetition (cyclic).
The randomize() method is used to generate random values for the random variables.
The pre_randomize() and post_randomize() are callback functions which will be automatically called right before/after function randomize().
The rand_mode() method is used to ENABLE or DISABLE the randomization of specific random variables or all random variables of class.
rand_mode(0) disables randomization.
rand_mode(1) enables randomization.
3. Example:
Output
$urandom(seed): generate 32-bits unsigned value. "seed" is optional.
$random(seed): generate 32-bits signed value. "seed" is also optional.
$random_range(int unsgined max_value, int unsigned min_value = 0): generate 32-bits unsigned value within the specificed range.