From Arthur C. Clarke's The Songs of Distant Earth:
The President of Thalassa had been in office for only two months and was still unreconciled to his misfortune. But there was nothing he could do about it, except to make the best of a bad job for the three years it would last. Certainly it was no use demanding a recount; the selection program, which involved the generation and interleaving of thousand-digit random numbers, was the nearest thing to pure chance that human ingenuity could devise.
There were exactly five ways to avoid the danger of being dragged into the Presidential Palace (twenty rooms, one large enough to hold almost a hundred guests). You could be under thirty or over seventy; you could be incurably ill; you could be mentally defective; or you could have committed a grave crime. The only option really open to President Edgar Farradine was the last, and he had given it serious thought.
Yet he had to admit that, despite the personal inconvenience it had caused him, this was probably the best form of government that mankind had ever devised. The mother planet had taken some ten thousand years to perfect it, by trial and often hideous error.
As soon as the entire adult population had been educated to the limits of its intellectual ability (and sometimes, alas, beyond) genuine democracy became possible. The final step required the development of instantaneous personal communications, linked with central computers. According to the historians, the first true democracy on Earth was established in the (Terran) year 2011, in a country called New Zealand.
Thereafter, selecting a head of state was relatively unimportant. Once it was universally accepted that anyone who deliberately aimed at the job should automatically be disqualified, almost any system would serve equally well, and a lottery was the simplest procedure...