Randomization of selected variables from a huge set of rand variables in a transaction class

I have a transaction class with 30 rand variables. One of the rand variable is OPCODE and it can take values from 1 to 100. For each OPCODE value, I want only a set of variables to be randomized. What’s the best way to do it considering the performance of the tool?

In reply to BHEEMA THANGAVELU:

I’m not sure if 30 is a huge numebr of variables for randomization. Nevertheless, if you want to switch off certain variables for randomization you can do this using the method rand_mode().
See the details in SV Standard 2012, chapter 18.8 Disabling random variables with rand_mode()

*In reply to chr_sue:*Your suggestion will not work if you try to change the rand_mode of a variable during a call to randomize().

In reply to BHEEMA THANGAVELU:
You may want to look at SystemVerilog randsequence construct. It was speciifically aimed at generating random instruction streams. It’s main drawback is it’s not OOP friendly in that certain kinds of behavior might be difficult to override.

If you don’t know beforehand what the opcode is going to be, what are you expecting the value of the variables you don’t randomized to be? You might just just add a constraint that setts them to a default value i.e.

constraint cpcode1 { OPCODE == 1 -> {var1 == default1; var2 == default2; }

You could also do something like

constraint cpcode1 { OPCODE == 1 -> {var1 == const'(var1); var2 == const'(var2); }

This says: if OPCODE is 1, constrain var1 and var2 to retain the values they had before the call to randomize().

If you only need to randomize a few variables based on the opcode, it might be easier to randomize opcode separately first, then do a case branch calling randomize on the selected variables.

case (OPCODE)
1: handle.randomize(var1,var2);
2: handle.randomize(var1,var3);
3: handle.randomize(var2,var3,var4);
...
endcase

In reply to dave_59:

Using rand_mode works perfectly for me. Having an object t with a data field var1:

t.var1.rand_mode(0);
void’(t.randomize);

*In reply to chr_sue:*chr_sue, That is using rand_mode() before calling randomize(). The problem is when you want to turn of rand_mode conditionally based on another random variable.

Thanks Dave,
I have achieved what I wanted with your suggestion.

  • BHEEMA THANGAVELU

In reply to BHEEMA THANGAVELU:

You are welcome. Which suggestion did you take?

In reply to dave_59:

In reply to BHEEMA THANGAVELU:
You are welcome. Which suggestion did you take?

Randomized OPCODE separately first, then did a case branch calling randomize() on selected variables.