Jump to content

How to only create a dynamic array and not do randomize on 'rand int a[ ]' in sequence item?

Recommended Posts

I have a dynamic array in sequence item as below:


rand int array_size;

rand int a [];


constraint c_order {solve array_size before a;};

constraint c_size { a.size() == array_size;};



In some tests, I hope to only create the array according to the randomized value of array_size but not do randomize on the value of it. Is there any way I can do that?



Link to comment
Share on other sites

Why is it you don't want the elements of array a to be randomized? If it is because you want the array values to be 0, then just add that constraint - foreach(a) a == 0;


Most time, I expect random value to test DUT. But sometimes I hope to get some simple patterns to test my verification environment, for example I expect the size is random but the value are constant or in/decreasing etc.


If I use foreach, could I turn it off when I expect random value?

Link to comment
Share on other sites

You can put the foreach constraint that dave_59 suggested in a separate constraint block and disable that using constraint_mode(0). Ex;

// somewhere in your class
constraint fixed_vals_c {
  foreach (a[i])
    a[i] == 0;

// somewhere where you randomize
some_obj.randomize();  // will gen random vals for array
Link to comment
Share on other sites

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.

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...