On older cars, it seems to function at random

On most you will probabaly find someone has disconnected the alarm brain under the passenger floor, due to alarm going off on its own.
If its working right, when the doors are locked, and a door, trunk or hood gets opened, it sets it off. Can also be set off by lifting the car, like being towed.
Turn it off by unlocking the car.