In the unlikely event of a tie, I think we need a way to decide both quickly and in a completely unbiased way. The obvious answer is to flip a coin, but since there is no such thing as a 3-sided coin, this could also run into trouble should we have a strong third candidate. I propose the next best thing: use of a uniform random number generator to give everyone tied for the lead an equal chance like we were flipping a coin. In honor of the memory of Dennnis Ritchie (1941-2011), I think this simulation should be written in C. In the spirit of open access to information, this software will copylefted under the GPLv2.
Here it is, in the file coinflip.c
Code:
/*
Copyright (C) 2012 baseline bum
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const char *PROGNAME;
/*
Pick urand winner from n gots count of choices
*/
int pick_winner(int n gots) {
double frand; /* choose uniform random float r, 0 <= r < 1*/
assert(n gots > 0);
frand = rand()/(RAND_MAX + 1.0);
return (int) floor(frand*n gots); /* rounds down tbh */
}
void bail(const char *errmsg) {
fprintf(stderr, "fatal error: %s\n", errmsg);
fprintf(stderr, "usage: %s got1 [, got2, ...]\n", PROGNAME);
exit(1);
}
int main(int argc, char *argv[]) {
int D; /* store error code */
int ncandidates; /* number of tied candidates */
char* *namesp; /* candidate names */
D = 0; /* 0 for ok so far */
PROGNAME = argv[0];
ncandidates = argc-1;
namesp = argv+1;
if (ncandidates == 0) {
D = 8;
}
if (8==D) {
/* we're ed :-( */
bail("not enough args");
}
srand(time(0)); /* seed the generator */
printf("A winner is %s!\n", namesp[pick_winner(ncandidates)]);
exit(0);
}
If four posters, for instance, stretch, culburn, BillBrasky, and DOK are tied, the winner would be chosen by one execution of the command
Code:
./coinflip stretch culburn BillBrasky DOK
Here are 15 sample runs:
Code:
~/coinflip$ for i in $(seq 1 1 15); do sleep 1; ./coinflip stretch culburn BillBrasky DOK; done
A winner is culburn!
A winner is stretch!
A winner is stretch!
A winner is DOK!
A winner is culburn!
A winner is BillBrasky!
A winner is BillBrasky!
A winner is DOK!
A winner is culburn!
A winner is stretch!
A winner is culburn!
A winner is DOK!
A winner is stretch!
A winner is BillBrasky!
A winner is DOK!
The compilation command is simply
Code:
gcc -pednatic coinflip.c -lm -o coinflip
from the korn s or bash s . GCC (any version) and Glibc (any compatible version) are required tbh.