In reply to Rahulkumar:
Hello! Here is my code:
class sample;
rand bit [3:0] array [10];
rand int i;
constraint elements {
foreach (array[i])
{
if (i >= 5 && i <= 9)
array [i] > array [i+1];
else if (i == 0 && i <= 4 )
array [i] < array [i+1];
}
}
endclass
module array_elements;
initial begin
sample s = new;
s.randomize();
foreach (s.array[i])
$display("array[%0d] = %0d",i,i);
end
endmodule
Here is the output:
array[0] = 0
array[1] = 1
array[2] = 2
array[3] = 3
array[4] = 4
array[5] = 5
array[6] = 6
array[7] = 7
array[8] = 8
array[9] = 9
I removed the cconstraint and the result still holds.