Reversing the array elements in a array without using reverse keyword

In reply to Manikanta Kopparapu:

Please, use code tag. It will provide easy visibility over code.
Btw, Your constraints are conflict due to below 2 condition contradicting each other.


  // this constraints assign array_1[0] = 0, array_1[1] = 1 ... array_1[4] = 4; 
  constraint addr_unique_values{ 
    foreach(array_1[i]) array_1[i]==i;
  }
  
  // in this line you are doing
  // array_1[0] = array_1[4] ==> array_1[0] = 4 which is contradicting with array_1[0] = 0;
  // So, your constraints is conficting.
  uaeg_1.randomize() with { 
    foreach(array_1[i]) array_1[i] == array_1[(array_1.size()-1) - i];
  };

And also in order to reverse array you not need to randomize again.
Simple streaming operator is enough to archive this. ( See below code )


class unique_array_example;
  
  rand bit [7:0] array_1[];
  
  constraint addr_size{
    array_1.size() == 5;
  }
  
  constraint addr_unique_values{ 
    foreach(array_1[i]) array_1[i] == i;
  }
  
endclass : unique_array_example

module abc();
  
unique_array_example uaeg_1;
  
initial begin
uaeg_1 = new();

//This loop is for the unique array values
// Note : - I dont know why you use repeat 1. It has not meaning.  
repeat(1) begin
  uaeg_1.randomize();
  foreach(uaeg_1.array_1[i]) begin
    $display("the value of a is %d and the value of is %d ",uaeg_1.array_1[i],i);
  end
end

$display("Before:- \n%p",uaeg_1.array_1);
uaeg_1.array_1 = {<<8{uaeg_1.array_1}};
$display("After:- \n%p",uaeg_1.array_1);
                
//uaeg_1.randomize() with{ foreach(array_1[i])
//  array_1[i] == array_1[ (array_1.size()-1) - i];
//};
   
foreach(uaeg_1.array_1[i]) begin
  $display("the value of in reverse array a is %d and the value of is %d ",uaeg_1.array_1[i],i);
end

end
endmodule

Thanks!