Generate randc behavior from rand variable:

It’s easy to get the first cycle of random numbers by pushing values on a list in post_randomize() and adding a constraint that keeps the values in the list excluded from the next solution.

class A;
   rand mytype_t myvar;
   mytype_t list[$];
   constraint cycle { unique {myvar,list};}
   function void post_randomize;
     list.push_back(myvar); //storing each myvar into list[$]
   endfunction 
endclass

The real problem is knowing when to start the cycle over by clearing the list. If the exact number of possible values for myvar is known, you can add a pre_randomize() method that deletes the list when hitting that limit.

function void pre_randomize;
 if (list.size() == limit) 
   list = {}; //delete queue
endfunction

Otherwise you will have to check the result of calling randomize() and assume it fails because it has exhausted the list of values.

About the author

The Art of Verification

Hi, I’m Hardik, and welcome to The Art of Verification.

I’m a Verification Engineer who loves to crack complex designs and here to help others commit to mastering Verification Skills through self-learning, System Verilog, UVM, and most important to develop that thought process that every verification engineer should have.

I’ve made it my mission to give back and serve others beyond myself.

I will NEVER settle for less than I can be, do, give, or create.

View all posts

1 Comment

  • Another way I tried.
    class rranc ;
    rand bit [15:0] val;
    int qval[$];

    constraint c_r{
    !(val inside {qval}) ;
    }

    function void post_randomize();
    if(qval.size >= 2**$bits(val)-1)
    qval = {};
    qval.push_back(val);
    endfunction
    endclass

    module top;
    initial begin
    rranc r = new ;
    repeat(32) begin
    r.randomize();
    end
    $display(“%p”,r);
    end
    endmodule