In general, testing was done randomly. That is, we never knew when it would happen ahead of time, and we never knew which numbers would be picked that day. They went by the last digit in your SSN. For example, at morning quarters it would be announced that all people with a SSN ending in 7 had to report to room such-and-such for urine testing. We went to the room to fill out the paperwork, and then one at a time go with an observer to the restroom.
Chain of custody was very important. Any little flaw in the procedure and the test results were thrown out. When there was a question about the results, it was always ruled in favor of the military member.
I don't know how it is today.
I don't know about today. I'll have to ask around. When I first served in the early 70's drug use was rampant and in the open, especially weed. People stood around outside their barracks smoking pot and offering it to passersby. We were coached to lie on the forms that we filled out about drug use.
After Vietnam the military got harsh about drug use. Once urine testing was perfected it seemed to drop. Also, the draft ended so the all-voluntary military attracted people who wanted to be there and didn't need drugs to escape military life. They were more career oriented and didn't want to jeopardize their careers.
When I was a Chief, one of my duties was to observe female officers during the urine test. Believe me, it's no more fun observing than being observed. Ugh!