Hello! Look at the below code. Im trying to assign the elements as follows:
class packet;
rand int array [] [] []; //diff b/w randc bit [3:0] [1:0] array [] [] [] and randc bit [7:0] array [] [] []
randc int size_i, size_j, size_k;
static constraint c1 {
array.size == size_i;
foreach (array [size_i]) {
array [size_i].size == size_j;
foreach (array [size_i,size_j]) {
array [size_i][size_j].size == size_k;
}
}
} //c1 is the constraint to randomize rows, columns and height of a 3d array
static constraint c2 {size_i > 0; size_j > 0; size_k > 0;}
constraint c3 {size_i <= 5; size_j <= 5; size_k <= 5;}
constraint c4 {size_i != size_j && size_j != size_k && size_i != size_k;}
constraint c5 {unique {array};}
static constraint c6 {
foreach (array [size_i]) {
foreach (array [size_j]) {
foreach (array [size_k]) {
if (size_i % 2 == 0) {
if (size_j % 2 == 0) {
if (size_k % 2 == 0) {
array [size_i] [size_j] [size_k] == 222;
}
else if (size_k % 2 != 0) {
array [size_i] [size_j] [size_k] == 221;
}
}
if (size_j % 2 != 0) {
if (size_k % 2 == 0) {
array [size_i] [size_j] [size_k] == 212;
}
if (size_k % 2 != 0) {
array [size_i] [size_j] [size_k] == 211;
}
}
}
if (size_i % 2 != 0) {
if (size_j % 2 == 0) {
if (size_k % 2 == 0) {
array [size_i] [size_j] [size_k] == 122;
}
if (size_k % 2 != 0) {
array [size_i] [size_j] [size_k] == 121;
}
}
if (size_j % 2 != 0) {
if (size_k % 2 == 0) {
array [size_i] [size_j] [size_k] == 112;
}
if (size_k % 2 != 0) {
array [size_i] [size_j] [size_k] == 111;
}
}
}
}
}
}
}
endclass
module md_array_foreach_constraint;
initial
begin
packet pkt = new;
$display("\n----------------------------------------DISPLAYING ARRAY ELEMENTS-----------------------------------------------\n");
repeat (2)
begin
pkt.randomize();
$display ("\nThe dimensions of the randomized 3d array: Rows [i] = %0d , Columns [j] = %0d , Height [k] = %0d",pkt.size_i,pkt.size_j,pkt.size_k);
for (int i = 0; i < pkt.size_i; i++)
begin
for (int j = 0; j < pkt.size_j; j++)
begin
$display ("\t"); //how is this tab space working in the program?
for (int k = 0; k < pkt.size_k; k++)
begin
$display ("array [%0d]\t[%0d]\t[%0d] \t=\t %0d",i,j,k,pkt.array[i][j][k]);
end
end
end
$display ("\n-----------------------------------------------------------------------------------------------------------");
end
end
endmodule
Can you please tell me whats wrong with the code