Constraint question

In the code snippet below, when I do a descr.randomize(), I want the mem_id to be randomized such that the current “mem_id” is NOT the same last 6 mem_ids. Any inputs on how to achieve this?

class my_descriptor;
  rand bit [63:0] data;
  rand bit[2:0] mem_id;
  
  
endclass  


module my_test;
  my_descriptor descr;
  
  function void run();
      descr = new();
    repeat(500) begin
        assert(descr.randomize());
        $display("data = %d, mem_id = %d \n", descr.data, descr.mem_id);
      end  
   endfunction
  
  
  initial begin
    run();
  end  
  
endmodule  

In reply to Verif Engg:

You can use randc qualifier for mem_id, You’ll get all 8 values before repeating
previous values.

randc bit[2:0] mem_id;

Or,

class my_descriptor;
  rand bit [63:0] data;
  rand bit[2:0] mem_id;

  bit [2:0] prev_mem_id[$:5];  //Limit queue size

  constraint c1{
    foreach(prev_mem_id[i]){
      mem_id != prev_mem_id[i];
    }
  }

  function void post_randomize();
    prev_mem_id.push_back(mem_id);
    //prev_mem_id.push_front(mem_id);
  endfunction
endclass

In reply to mayurkubavat:
FYI, only push_front() gives you the behavior of discarding the oldest element off a bounded queue.

Also, randc is not relevant to what the OP has asked.

In reply to dave_59:

Oh, correct! randc will not work here. I was expecting push_front() will also work in a same way.
Also, another way without the use of foreach loop in above snippet is inside operator,

constraint c1{
  !(mem_id inside {prev_mem_id});
}

In reply to MayurKubavat:

another way to get unique value other than the prev 6 values:


constraint c1{
  unique{prev_mem_id, mem_id};
}

And is there any reason why ‘randc’ will not work ??
(Because it does not use past 7 values instead of 6-values right ??)