Unconstrained randomization generates any possible value. For a 32-bit address, that's 4 billion possibilities! Most of those might be invalid for your DUT. Constraints let you focus on legal and interesting values.
Basic Constraint Syntax
class Packet;
rand bit [31:0] addr;
rand bit [7:0] length;
rand bit read_write;
// Constraint block
constraint addr_range {
addr >= 32'h1000;
addr < 32'h2000;
}
constraint valid_length {
length inside {[1:64]}; // 1 to 64 bytes
}
endclass