Constraint Question

In reply to kmishra:

From the statement which is “nearest”, I guess that you have another variable(s) other than A and B. The case you state says that B must be nearest to A, so if we assume that you have a sequence item which is named as “dummy_seq_item”, you can write sth like this:

--------------Your seq_item code-------------------
class dummy_seq_item extends uvm_sequence_item;
`uvm_object_utils(dummy_seq_item)

function new(string name=“dummy_seq_item”);
super.new(name);
endfunction

rand int A;
rand int B;
rand int C;

constraint A_is_first{
solve A before B;
solve A before C;
}
constraint which_is_closer{
((A%6) == 0 ) → ( B>C );
};

endclass

let’s say, if you have D, E and etc. other than B and C, you can write a swap function instead of right hand side of the constraint. If it returns 1, constraint will be valid.