Constraint for two dimensional array

In reply to Subbi Reddy:

I tried my best to understand from you tried to convey. See if the logic is right. If it isn’t, please be more clear with what you need.

class packet;

	rand int array [5] [5];
	
	constraint elements_range_fix {
	
			foreach(array[i,j]) {
								
				array[i][j] inside {[1:5]};
	
							}
	
					}
							 
	constraint element_pattern_fix {
	
	     foreach(array[i,j]) {
										
	         if(i == 0) {
																								
		   foreach(array[j]) {
																													
			if(j == 0 || j < 4) {
																													
				array[i][j] < array[i][j + 1];
																			
							}
																			
			                   }
																																
				   }
																					 
		if(i == 1) {
																	
		   foreach(array[j]) {
																						
			if(j == 0 || j <= 2 ) {
																													
			    array[i][j] < array[i][j + 1];
				  
                                                         }
																	
		       else if(j == 3 || j < 4) {
																													
			    array[i][j] > array[i][j + 1];
																													
				                           }
																																	 
		                            }
																												 
		               }
																					 
		if(i == 2) {
																	
		  foreach(array[j]) {
																						
		     if(j == 0 || j <= 1 ) {
																													
			 array[i][j] < array[i][j + 1];
						
                                                      }
																	
		     else if(j == 2 || j < 4) {
																													
			array[i][j] > array[i][j + 1];
																													
					                  }
																																	 
                                          }
																												 
			       }
																	
	        if(i == 3) {
																	
		   foreach(array[j]) {
																						
		       if(j == 0 || j < 1 ) {
																													
				array[i][j] < array[i][j + 1];
						
                                                       }
																	
		       else if(j == 1 || j < 4) {
																													
			        array[i][j] > array[i][j + 1];
																													
							  }
																																	 
					}
																												 
			   }
																					 
	        if(i == 4) {
																	
		   foreach(array[j]) {
																						
			if(j == 0 || j < 4) {
																													
				array[i][j] > array[i][j + 1];
																																		
							}
																																	 
					    }
																												 
		                 }
										
																 
                         }	  

                }
							 						 
endclass

module diagonal_array;

	initial 
	
		begin
		
			packet pkt = new();
			
			pkt.randomize();
			
			$display("\narray : %0p",pkt.array);
			
		end
		
endmodule