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.

One thought on “Generate randc behavior from rand variable:”

  1. 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

Comments are closed.