Constraint randomization among multiple sequence items

Hi,

What is the typical way in UVM world when come to resolve some case like below?
Say I have mulpitle sequence items inside a sequnce, which will randomly generate a color (typedef enum {RED, BLACK, BLUE} COLOR;) token. The contraint we have is normally applied to the current item. What if we hope have some control among multiple items, like if the first items give us RED, the next one should be either BLACK or BLUE.

I’m trying to learn some constraint practise. I found most of the constraint material are focused on the sytax. Would there be any constraint tutorial involved more with UVM?

Thanks.

In reply to Renjie Lu:

You need to create a state machine. See Where is pre_randomize() used ? | Verification Academy

In reply to dave_59:

Hi Dave,
What if the case is changed as " when RED got hit twice successively, the third one should be BLACK or BLUE "? Not sure if pre_randmoize still work in such requirement.

In reply to Renjie Lu:

In reply to dave_59:
Hi Dave,
What if the case is changed as " when RED got hit twice successively, the third one should be BLACK or BLUE "? Not sure if pre_randmoize still work in such requirement.

Your requirement is getting more complicated, it is hard to use constraint. I think, using “randsequence” is better solution for your cases, you can control any order of sequence items.

In reply to Renjie Lu:

You will need to add more state variables to capture previous

rand token rvalue;
token value1 value2;

function void pre_randomize ();
  value2 = value1;
  value1 = rvalue;
endfunction

Then you can use the expression value1==RED && value2 == RED in your constraint.