I want to generate random values that are cyclic in nature, or in other words they are completely exhaustive of their possible values.
- Is there any way to do this using Scope Randomization, using a UNIQUE constraint? (having declared variable as rand int)
- If not then any other solutions that might avoid declaration of a new class?
rand int variable_x;
if(! std::randomize(variable_x) with {variable_x >0; variable_x < varible_x_threshold ; unique{variable_x} ;}begin
`uvm_error(get_type_name(),"RANDOMIZATION FAILED")
end
The above snippet throws no error, but I don’t see variable_x going around in a cyclic manner.
Okay I have found the solution to this issue. Consider the following snippet:
`define addr_max_value 32
rand bit[4:0] addr_array[addr_max_value];
int addr_to_be_driven;
int addr_counter;
if(!std::randomize (addr_array) with { unique {addr_array};
foreach(addr_array[j]) begin
addr_array[j] < addr_max_value;
end })begin
`uvm_error(get_type_name(), "Randomization Failure")
end
//This has generated a random, exhaustive pattern of array elements that can be assigned further to required variables inside a loop, consider:
for(addr_counter =0; addr_counter < addr_max_value ; addr_counter++) begin
addr_to_be_driven = addr_array[addr_counter];
// addr_to_be_driven can now be used further as required
end