Randomization with Constraint

I want to randomize a variable such that when a particular values comes into it then the next value of randomization should be fix.
Like below example,

typedef enum {test1, test2, test3, test4, test5, test6, test7, test8, test9, test10} test;
rand test tst;

Now what I want is randomize tst in such a way that when the random value of tst is “test5” then for next randomization it should have value test6 only.
Suppose we randomize tst for 5 times then it can have any value from enum but if the value is test5 then for next random it should be test6. Let say for 5 times randomization on 3rd time randomization tst got value test5 then on 4th time randomization it should get value test6 only.
tst can get value as test6 anytime but for test5 i want such condition and yaa for last randomization test5 can come individually i.e. for 5th time randomization tst can have any value from enum.

Thanks in advance

In reply to om30:

constraint test5_6 { const'(tst) == test5 -> tst == test6; }

Thank You dave_59 sir
Can I get explanation for your solution as I didn’t got how const’ works here.
Can you please give some idea.
Also I want that the last randomized value of tst should not be test6. I tried in many ways by my understanding but I am not able to achieve the task.
I have to put both constraint parallelly like tst should get test6 if test5 comes and the last randomized value should not be test6.

Thanks in advance

In reply to om30:

See this about const.

You need to describe how the last randomization gets determined.

Thank You for the link. I can now understand how const’works here.
Other scenario which I have is lets say tst is randomized for 10 times then the randomized value of tst for 10th time should not be test6.
Like the constraints we put
constraint test5_6 { const’(tst) == test5 → tst == test6; }
as per your solution in this constraints only I want that test6 should not come on last randomization. So it means on last randomization tst can have any value from enum but not test6.

Thanks in advance

In reply to om30:

If you’re going to randomize individually then you need a counter up or down.

class A;
  typedef enum {test1, test2, test3, test4, test5, test6, test7, test8, test9, test10} test;
  rand test tst;
  rand int count_down=10;

  constraint timer     { const'(count_down)-1 == count_down; }
  constraint last_test { count_down == 0 -> tst != test6; 
                         count_down == 1 -> tst != test5; }
  constraint test5_6   { const'(tst) == test5 -> tst == test6; }
endclass

A slightly different approach for this case is doing one randomization of an array of test selections. Then the constraints are easier to write.

class A;
  typedef enum {test1, test2, test3, test4, test5, test6, test7, test8, test9, test10} test;
    rand test tst[$]= '{10{test1}};
 
    constraint test5_6 {foreach (tst[i]) i> 0 -> tst[i-1] == test5 -> tst[i] == test6;}
  constraint last_test { tst[$] != test6;}
endclass