Inline constraints are specified using the with clause after
randomize(). They act as additional constraints on top of
the class constraints.
class Packet;
rand bit [31:0] addr;
rand bit [7:0] size;
constraint valid_size {
size inside {[1:64]};
}
endclass
Packet p = new();
// Default randomization
p.randomize(); // Any size from 1-64
// With inline constraint - add more restrictions
p.randomize() with {size == 32;}; // Force size = 32
p.randomize() with {addr < 1000;}; // Add addr restriction
p.randomize() with {
size inside {4, 8, 16};
addr[1:0] == 0; // Multiple constraints
};
How It Works
Inline constraints are added to class constraints. Both must be satisfied. If they conflict with a hard constraint, randomization fails!