During each randomization I would have an address( or even multiple addresses ) . During next call to randomization same addresses shouldn’t be obtained . This is till all possible addresses are observed post-randomization .
Eg : Lets say I have max 4 addresses ( 0 to 3 ) . So 1st randomization gives me address 0 and 2 , during 2nd randomization I can get value 1 and 3 OR only 1 of them in which case during call to 3rd randomization I obtain the last remaining index .
The 1st randomization call can give me only 1 address too . So basically I need minimum of 1 randomization call and max of 4 randomization calls to achieve all addresses .
// Assuming addresses of 0 to 3 are possible
bit [1:0] q2[$] ; // Storage element for previous values
rand bit [1:0] q1 [$] ;
constraint SIZE { q1.size() inside { [0 : ( 3 - q2.size() ) ] } ; }
constraint VAL { unique { q1 , q2 } ; }
function void post_randomize() ;
foreach( q1[i] )
begin
q2.push_back( q1[i] ) ;
end
endfunction
[Q1] Any alternate solution possible ? Can I achieve the same without helper array q2 ( Using const’() maybe ) ?
[Q2] What if I enhance the question so that ::
Now I have a memory ( unpacked array ) with possible addresses same as the random address variable
So can I constraint the memory such that only those memory address location obtained by q1 are randomized ?
Eg : If 1st randomization gives us q1 as 0 and 1 , so only memory location 0 and 1 would be randomized
During 2nd call which gives me q1 as 2 ( memory location 0 and 1 will have previous values ) , memory location 2 will be randomized .
**The reason I am confused with this is , I know I can't use random variables as indexes so don't know how to proceed .**
I want to obtain it via constraints not via post_randomize() preferably .
Thanks ,
TC