Logger Posted March 1, 2016 Report Share Posted March 1, 2016 This section of the LRM is vague. 18.11 In-line random variable controlWhat 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 Quote Link to comment Share on other sites More sharing options...
dave_59 Posted March 1, 2016 Report Share Posted March 1, 2016 What is not clear is why you expect c.a to be 10. Because of the assignment p.c = c;, c.a and p.c.a are the same random variable. Quote Link to comment Share on other sites More sharing options...
mastrick Posted March 1, 2016 Report Share Posted March 1, 2016 Hi Dave, If you just had "c.a = 10; p.c = c;", you would certainly expect c.a (and p.c.a) to be 10 afterwards. I think the question is why p.randomize(c. does not mean that c.a is a state variable, so it is still 10 after the randomize. Mark Quote Link to comment Share on other sites More sharing options...
tudor.timi Posted March 2, 2016 Report Share Posted March 2, 2016 I tried the code on EDAPlayground and it worked as expected (c.a was 10 and then 50). Quote Link to comment Share on other sites More sharing options...
Logger Posted March 3, 2016 Author Report Share Posted March 3, 2016 Indeed! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.