Jump to content

In-line random variable control


Recommended Posts

This section of the LRM is vague.
 
18.11 In-line random variable control

What is the expected behavior for the following code?

class child;
    rand int a;
    rand int b;

    constraint cb {
        a inside {[0:100]};
        b inside {[0:(2*a)]};
    }

endclass

class parent;
    //Uncomment to force desired behavior: rand int a;
    rand child c;
    constraint cb {
        //Uncomment to force desired behavior: a == c.a;
        c.b >= c.a;
    }

//Uncomment to force desired behavior:    function void pre_randomize();
//Uncomment to force desired behavior:        a = c.a;
//Uncomment to force desired behavior:    endfunction

endclass

module top;
    initial begin
        parent p = new;

        child c = new;
        c.a = 10;
        p.c = c;
        void'( p.randomize( c.b ) );
        $write( "c.a == %0d ( expecting 10 )\nc.b == %0d\n\n", c.a, c.b );

        c = new;
        c.a = 50;
        p.c = c;
        void'( p.randomize( c.b ) );
        $write( "c.a == %0d ( expecting 50 )\nc.b == %0d\n\n", c.a, c.b );

        $finish;
    end
endmodule

In my simulator I get:

 

c.a == 71 ( expecting 10 )

c.b == 111
 
c.a == 14 ( expecting 50 )
c.b == 15
 
$finish called from file "nested.sv", line 42.
$finish at simulation time                    0
 
Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...