SSingh,
I see my previous solution using old SV-2005/9 syntax doesn’t fully meet your requirement, sorry spoke too fast perhaps. However when you say:
Since the order has to be random,
constraint data_values { foreach(data[i]) data[i+1] > data [i] ;}
is not something I want.
Why not use shuffle in post_randomize? Point is - you are asking the solver to go and do all the hardwork by writing some fancy expression to simply do:
- Fill all values from 0…15
- Shuffle the order
IMHO - this is bad for performance and an unnecessary overkill of available horse power. Sure Vishu’s code looks nice, but hopefully you agree it is not so intuitive. We generally recommend KISS principle (KISS principle - Wikipedia). Consider the below code - this would achieve what you intended in a simpler manner - relatively speaking. But - you do have a fancy code choice, thanks to Vishu!
constraint cst_ascend { foreach(data[i])
i > 0 ->
(data[i] > data [i-1]) ;}
function void post_randomize;
this.data.shuffle;
$display("%p",this);
endfunction : post_randomize
The above code scales nicely for 1 - to - SIZE-1 array size. Since it uses one foreach loop in constraints, tools will have it easy and is easier to read/maintain/explain to others.
Nice topic, BTW.
HTH
Ajeetha, CVC