Can any one help me to write a constraint for random value in random position
In reply to shravanikuchana777@gmail.com:
We can only help if you explain in more detail. How is this different from randomizing an array with no constraints? Show us the declaration of the array and some examples of valid and invalid solutions.
Thank you very much for your reply
I’m taking an array of 6elements each having 4bits
I want the each element of that array to have a random values in random position
For that I wrote a constraint shown below
I want to know whether it is correct or not…
class array;
rand bit [3:0] array1[6];
constraint arrayvalues { foreach(array1[i]) array1[i]=$random;}
function void post_randomize();
array1.shuffle();
endfunction
function void display();
$display("array1 = %p",array1);
endfunction
endclass
module TB
array pkt;
initial begin
pkt = new();
pkt.randomize();
pkt.display();
end
endmodule
In reply to shravanikuchana777@gmail.com:
As the array is declared as rand, when the object is randomized random values will be generated for the array elements, again no need to write constraint for array.