It was November 1811 and Spain's parliamentarians were holed up in Cadiz, under siege, while the rest of the country was in the hands of Napoleon, who had put his brother, Joseph Bonaparte on the Spanish throne.
As the Spanish War of Independence (also known as the Peninsular War) raged, the Cortes de Cádiz (which was Spain's first national assembly) continued to legislate, refusing to accept the rule of "Rey José I".
The most famous result of the Cortes' legislation was the Cadiz Constitution, also known as 'La Pepa', which, declared in 1812, was one of the earliest constitutions in the world and the most liberal of its time.
Before this, though, the members of this parliament had voted to introduce a state moneymaking tool that still exists to this day. On 23 November 1811 the members of the Cortes voted unanimously in favour of bringing in a new lottery to raise funds to boost resistance against the Napoleonic troops.
The idea came from Ciriaco González Carvajal, minister of the Council of the Indies, who proposed copying a system used in Nueva España, now Mexico.
A lottery did already exist in Spain at the time, however, a numbers system imported by King Carlos III from Naples in 1763. This became (and still is) known as "La Primitiva", while González Carvajal's new ticket scheme was known as the Lotería Moderna and the Lotería Nacional.
The first draw of the new lottery took place on 4 March 1812, just two weeks before La Pepa was declared. At first, tickets were only available in Cadiz and San Fernando, but as the Napoleonic troops withdrew, it expanded to Ceuta and the rest of Andalucía, and eventually the rest of Spain.
The last prize draw to be held in Cadiz was on 27 January 1814. After that it was moved to Madrid where the first draw there took place on 28 February 1814.
The Cadiz Constitution was short-lived, abolished after King Fernando VII returned to the throne in 1814.
The Lotería Nacional however, survived and draws still take place on Thursdays and Saturdays as well as the special draw for Christmas (with its famous Gordo prize) on 22 December and for Epiphany (El Niño) on 6 January.