Simulation not going forward if i use delay for each randomize of class object

info:

package class_pkg;
class rectangle;
	rand int lenght,width;

	function new(int l = 10, int w = 20);
		lenght = l;
		width = w;
		$display("from class rectangle:new: length = %d and width = %d",lenght,width);
	endfunction
	function int area();
		$display("from class rectangle:area: area = %d", lenght*width);
		return lenght*width;
	endfunction
endclass
class square extends rectangle;
	function new(int l = 10);
		super.new(l,l);
		$display("from class square:new: length = %d ",l);
	endfunction
endclass
endpackage

module tb;
import class_pkg::*;
rectangle rct1,rct2;
square sqr1,sqr2;
logic clk; 

initial begin 
	clk = 0;
	forever clk = #5 !clk;
end

initial begin 
	rct1 = new(20,30);
	sqr1 = new(20);
	rct2 = new();
	sqr2 = new();
	#100;

	// by passing cusom value while creating object
	$display($time,"Rectangle area = %d",rct1.area());
	$display($time,"Square area = %d\n",sqr1.area());

	// for default values inside the class
	$display($time,"Rectangle area = %d",rct2.area());
	$display($time,"Square area = %d\n",sqr2.area());

	// using randomization
	repeat(10) 
	begin	
		@(posedge clk);
       		rct2.randomize();
		sqr2.randomize();	
		$display($time,"RANDOMIZE: Rectangle area = %d",rct2.area());
		$display($time,"RANDOMIZE: Square area = %d",sqr2.area());
	end
end
endmodule

output:
run

from class rectangle:new: length = 20 and width = 30

from class rectangle:new: length = 20 and width = 20

from class square:new: length = 20

from class rectangle:new: length = 10 and width = 20

from class rectangle:new: length = 10 and width = 10

from class square:new: length = 10

from class rectangle:area: area = 600

100Rectangle area = 600

from class rectangle:area: area = 400

100Square area = 400

from class rectangle:area: area = 200

100Rectangle area = 200

from class rectangle:area: area = 100

100Square area = 100

quit

End time: 09:31:25 on Sep 10,2022, Elapsed time: 0:00:01

Errors: 0, Warnings: 0

=====================================

but in the above code, if i remove or comment the @(posedge clk) in the repeat block, here is the output and is as expected:


run

from class rectangle:new: length = 20 and width = 30

from class rectangle:new: length = 20 and width = 20

from class square:new: length = 20

from class rectangle:new: length = 10 and width = 20

from class rectangle:new: length = 10 and width = 10

from class square:new: length = 10

from class rectangle:area: area = 600

100Rectangle area = 600

from class rectangle:area: area = 400

100Square area = 400

from class rectangle:area: area = 200

100Rectangle area = 200

from class rectangle:area: area = 100

100Square area = 100

from class rectangle:area: area = 570685860

100RANDOMIZE: Rectangle area = 570685860

from class rectangle:area: area = -131359708

100RANDOMIZE: Square area = -131359708

from class rectangle:area: area = 1874853487

100RANDOMIZE: Rectangle area = 1874853487

from class rectangle:area: area = -1143184658

100RANDOMIZE: Square area = -1143184658

from class rectangle:area: area = 1666416198

100RANDOMIZE: Rectangle area = 1666416198

from class rectangle:area: area = -1357049832

100RANDOMIZE: Square area = -1357049832

from class rectangle:area: area = 1131627911

100RANDOMIZE: Rectangle area = 1131627911

from class rectangle:area: area = 933851776

100RANDOMIZE: Square area = 933851776

from class rectangle:area: area = 1659118711

100RANDOMIZE: Rectangle area = 1659118711

from class rectangle:area: area = -433249897

100RANDOMIZE: Square area = -433249897

from class rectangle:area: area = 725371862

100RANDOMIZE: Rectangle area = 725371862

from class rectangle:area: area = -1707424016

100RANDOMIZE: Square area = -1707424016

from class rectangle:area: area = 806064176

100RANDOMIZE: Rectangle area = 806064176

from class rectangle:area: area = -446701857

100RANDOMIZE: Square area = -446701857

from class rectangle:area: area = 1631562138

100RANDOMIZE: Rectangle area = 1631562138

from class rectangle:area: area = -603291980

100RANDOMIZE: Square area = -603291980

from class rectangle:area: area = -1141090826

100RANDOMIZE: Rectangle area = -1141090826

from class rectangle:area: area = 824529279

100RANDOMIZE: Square area = 824529279

from class rectangle:area: area = -401615008

100RANDOMIZE: Rectangle area = -401615008

from class rectangle:area: area = -1847494794

100RANDOMIZE: Square area = -1847494794

quit

End time: 09:33:51 on Sep 10,2022, Elapsed time: 0:00:01

Errors: 0, Warnings: 0

============================

why randomization not happening in case of delay (@(posedge clk)) ?

any help or suggestions are highly appreciated.

Thank you.

In reply to sudikuma:
You are missing a way for the simulation to end. You can either use a repeat loop instead of forever in the first initial block, to put a $finish at the end of the second initial block. Then you get the expected output in all cases.

In reply to dave_59:

Thanks a lot this helps.

Here is the final working one:

import class_pkg::;
import uvm_pkg::
;
define info(msg) uvm_top.uvm_report_info($psprintf("%m"),msg); define warning(msg) uvm_top.uvm_report_warning($psprintf(“%m”),msg);
define error(msg) uvm_top.uvm_report_error($psprintf("%m"),msg); define fatal(msg) uvm_top.uvm_report_fatal($psprintf(“%m”),msg);

module tb;
rectangle rct1,rct2;
square sqr1,sqr2;
logic clk;

initial begin
clk = 0;
forever clk = #5 !clk;
// repeat(100)begin
// clk = #5 !clk;
// end
end

//initial begin
// // uvm methods from uvm_pkg
// #100;
// uvm_top.uvm_report_info($psprintf(“%m”),“THIS IS AN INFO MESSAGE”);
// info("THIS IS AN INFO MESSAGE: USING define") // warning(“THIS IS AN WARNING: USING define”)
// error("THIS IS AN ERROR: USING define") // fatal(“THIS IS AN FATAL: USING define”)
//end

initial
begin
rct1 = new(20,30);
sqr1 = new(20);
rct2 = new();
sqr2 = new();
#100;

// by passing cusom value while creating object
$display($time,"Rectangle area = %d",rct1.area());
$display($time,"Square area = %d\n",sqr1.area());

// for default values inside the class
$display($time,"Rectangle area = %d",rct2.area());
$display($time,"Square area = %d\n",sqr2.area());

// using randomization
repeat(10) 
begin	
	@(posedge clk);
   		rct2.randomize();
	sqr2.randomize();	
	$display($time,"RANDOMIZE: Rectangle area = %d",rct2.area());
	$display($time,"RANDOMIZE: Square area = %d",sqr2.area());
end
$finish();

end
endmodule