From the FAA-AMPP
A covered employee shall only be randomly tested while the employee is performing safety-sensitive functions; just before the employee is to perform safety-sensitive functions; or just after the employee has ceased performing such functions.
This would be why deadheading at the end of a flight sequence would not apply.