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