They were often a way to try to boost sales. For instance, your penny into the machine might net you a variable number of cigarettes - normally just one or two, but occasionally you'd hit the 'jackpot' and get a full pack.
At least, that's my understanding.