Jump to content

Recommended Posts

Posted

Hi,

 

I want to randomize a variable defined in a function. The function is inside a package.

 

I tried declaring a class inside the package and taking the instance of that class in the function.

But that didnt work out as the object needs to be static.

 

I tried randomization() function, but the problem is the variable "k" can only have 2 value ie (5,9).

 

function foo()

 int k;

 void'(randomize(k)) with {k==5;k==9;});  // I am getting randomization failure in this case.

endfunction

 

Let me know how can this be resolved.

 

Thanks.

Posted

You have to do std::randomize(k) to randomize variables declared in the global scope. With respect to k's value, you just constrained it to be both '5' and '9' at the same time. You have to say "k inside { 5, 9 }".

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...