1
\$\begingroup\$

In the following code, I have 2 cyclic random variables in a class. One (an enumerated type) takes 3 possible values, and the other takes 288 possible values (due to a constraint). So, I expect to get unique values for 288*3 randomize calls before the values repeat again.

I tried to randomize using two different methods:

  • body: randomizes each variable independently, this results in 579 unique random values
  • body2: randomizes the whole class, this results in 674 unique random values

So am I getting less than 288*3 unique values ?

typedef enum logic [1:0] {a,b,c} DecodeMode_t;
class seq;
  randc integer CaseNum;
  randc DecodeMode_t DecodeMode;
  constraint cons {
    CaseNum > 0;
    CaseNum <= 288;
  }


  task print;
    $display("CaseNum=%0d, DecodeMode=%s", CaseNum, DecodeMode);
  endtask

  task body;
    repeat(288) begin
      randomize(CaseNum);
      repeat(3) begin
        randomize(DecodeMode);
        print;
      end
    end
  endtask

  task body2;
    repeat(288*3) begin
      randomize();
      print;
    end
  endtask

endclass

module tb;

seq myseq;
initial begin
  myseq = new;

  // This gives 674 unique results:
  //myseq.body2;

  // while this gives 579 unique results:
  myseq.randomize();
  myseq.print;
  myseq.body;
end
endmodule

I am running QuestaSim 10.7c simulation tool.

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

I found a solution on some discussion forum, is to put both variables in a struct, it has to be a packed struct, or else the compiler would complain. Here's how I changed the class:

typedef enum logic [1:0] {a,b,c} DecodeMode_t;
class seq;
  randc struct packed {
  integer CaseNum;
  DecodeMode_t DecodeMode;
  } rs;
  constraint cons {
    rs.CaseNum > 0;
    rs.CaseNum <= 288;
  }

  task print;
    $display("CaseNum=%0d, DecodeMode=%s", rs.CaseNum, rs.DecodeMode);
  endtask

  task body2;
    repeat(288*3) begin
      randomize();
      print;
    end
  endtask

endclass
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.