The story
Attested since at least 1833, on the second page of Galignani's Messenger: "amusing themselves by pitching quoits, spoiling halfpence at heads or tails with the gingerbread merchants, drinking beer, smoking, etc".
Etymology from Wiktionary, CC BY-SA 4.0.