Iteration of elements in an array declared as randc

Hi Forum,

As per LRM :

Arrays can be declared rand or randc, in which case all of their member
elements are treated as rand or randc.

On testing the following code across random seeds

class C;
 randc bit arr1[2];
 //randc bit [1:0] arr2[4];
endclass

C c1;
initial begin
  c1 = new();
  repeat(20) begin
   if(c1.randomize()) $display("Success with %0p",c1.arr1);
  end
end

With random seed1 I observe:

Success with 1 1

Success with 0 0

Success with 0 0  // Repeats 2nd row

Success with 1 1  // Repeats 1st row

Success with 0 0

Success with 1 1

Success with 0 0

Success with 1 1
.................

With random seed2 ( Eg: -sv_seed 3227964056 ) I observe:

Success with 1 0

Success with 0 1

Success with 1 1

Success with 0 0  // Note: First four rows are unique combinations

Success with 0 0  // Repeats 4th row on 5th call to randomize()

Success with 1 1

Success with 0 0  // Repeats 0 0 combination w/o observing 0 1 / 1 0

Success with 1 1
................

I expected that the first four calls to randomize() give me unique combinations ( as observed in the first 4 rows with seed2 ) whereas same isn’t observed with seed1

LRM 18.4.2 Randc modifier states:

The basic idea is that randc randomly iterates over all the values in the range
and that no value is repeated within an iteration.
When the iteration finishes, a new iteration automatically starts 

(1) With randc qualifier, how do arr1 elements iterate ?

(2) When does an iteration finish for arr1 ?

(3) Based on (1) & (2) when would a new iteration start for arr2 ?

(4) As a general statement: “For a randc array with elements N-bits wide and of size D”,

how many different patterns would be observed ( before next iteration starts ) ?

Thanks in Advance

  1. The LRM would be clearer if it said: Arrays can be declared rand or randc, in which case each of their member elements are treated as rand or randc. This means each array elements is treated as an indepdent randc variables.
  2. Each element in arr1 represents a 1-bit value, allowing for two possible states to iterate over.
  3. Each element in arr2 represents a 2-bit value, enabling four possible states to iterate over.
  4. The size of unpacked dimensions is irrelevant, only the width of each element matters.

Thanks Dave. Using arr2 I observe results:

Success with '{'h2, 'h1, 'h0, 'h1} 
Success with '{'h3, 'h0, 'h1, 'h2} 
Success with '{'h1, 'h2, 'h2, 'h3} 
Success with '{'h0, 'h3, 'h3, 'h0} // B/W Rows 1-4 each Index has iterated through 4 values 
Success with '{'h3, 'h3, 'h1, 'h2} 
Success with '{'h0, 'h1, 'h0, 'h0} 
Success with '{'h2, 'h0, 'h3, 'h1} 
Success with '{'h1, 'h2, 'h2, 'h3} // B/W Rows 5-8 each Index has iterated through 4 values 
Success with '{'h2, 'h3, 'h2, 'h0}