class packet;
rand bit bench_row1 [3][2];
function void display();
$display("no of students in first group",bench_row1);
//$display("student is[1] %s =",);
$display("---------------------------------------------------");
endfunction
function void post_randomize();
bench_row1 = '{ default:0};
while(bench_row1.sum() < 2)
begin
bench_row1[$urandom_range(2,0)][$urandom_range(1,0)] = $urandom_range(1,0);
$display("inside while looppppppppppppppppppppppp",bench_row1);
if(bench_row1.sum() == 2) break;
end
/*
if(bench_row1.sum() < 3)
do begin
bench_row1[$urandom_range(2,0)][$urandom_range(1,0)] = $urandom_range(1,0);
$display("inside if looppppppppppppppppppppppp",bench_row1);
end while( bench_row1.sum() != 2);
*/
endfunction
endclass
module ex;
packet pkt;
initial begin
pkt = new();
pkt.randomize();
pkt.display();
end
endmodule
i tried it with if and while loop, output i am getting is infinite times. actually it is not going inside if loop. how to break loop if condition bench_row1.sum() = 2 satisfies?