Constraint block

July 24, 2024 || Item:7.2.Constraints Block

The constraint block is used within a class to ensure that the random values generated for the variables meet certain criteria. It's a class member, so it must have the unique name within class. 

Like task or fucntion, constraint can be defined outside of class. 

The constraint can also be specificed directly within "randomization()" function call. 

Constrain from base class can be extended and modified in a derived class. This allows you to build upon existing constraints while adding new ones or overriding existing ones in a derived class. 

Constraints in base class will be overwritten in derived class if their name are the same. Otherwise, constraints in both classes will be combined.

Like randomization, we can disable a specific constraint or all constraints of class, using function "constrant_mode()".

Example

Output:



Comments:

Leave a comment: