Is there a way to generate unique values for a 16-bit rand variable every time I call the randomize method? I know that the unique keyword creates unique values for a set of variables when the randomize method is called. But I am interested in generating values that are unique to the values created with the previous randomize calls.
In reply to Krishna9:
module top ;
class rranc ;
rand bit [15:0] val;
int qval[$];
constraint c_r{
!(val inside {qval}) ;
}
function void post_randomize();
if(qval.size >= 2**$bits(val)-1)
qval = {};
qval.push_back(val);
endfunction
endclass
initial begin
rranc r = new ;
repeat(32) begin
r.randomize();
$display("%p",r);
end
end
endmodule
In reply to Krishna9:
// This will be helpfull
class A;
typedef bit [15:0] my;
rand my value;
my value_queue[$];
constraint gen{unique{value,value_queue};}
function void post_randomize();
value_queue.push_back(value);
if(value_queue.size()==(2**16)) value_queue={};
endfunction
endclass
module top;
A a;
initial begin
a=new;
for(int i=0; i<500; i++)begin
assert(a.randomize());
$write(" %d \t ",a.value);
end
end
endmodule