Hi,
How can we write a constraint for a random dynamic array to generate values in ascending order?
Regards,
Ronak
Hi,
How can we write a constraint for a random dynamic array to generate values in ascending order?
Regards,
Ronak
In reply to Ronak Patel:
class dynamic_array;
rand bit[3:0] myarray[];
constraint sz{myarray.size==5;}
constraint val{foreach(myarray[i]) if(i>0) myarray[i]>myarray[i-1];}
endclass
Hi Mada saimanasa,
do you have another method for same kind of constraint ?
Regards,
Ronak
In reply to Ronak Patel:
How about this?
class dynamic_array;
rand bit[3:0] myarray[];
constraint sz{myarray.size==10;}
constraint val{foreach(myarray[i]) myarray[i]==i;}
endclass
Both solutions answer your question. If there is something else that you are looking for, you need to provide more information so that others aren’t guessing what your requirements are.
In reply to cgales:
We can do one thing,
randomize of dynamic array without any constraint,
and then in post randomization we simply call .sort method for arrange all element in acceding order,
for same value of array element, we can call .unique method in constraint,so we get all different value of array.
May be this is good way to arrange dynamic array in acceding order.
Regards,
Ronak