If the function returns > 0, the first param should be sorted to a higher index than the second.
If the function returns < 0, the first param should be sorted to a lower index than the second.
If the function returns exactly zero, the parameters are left as they are.
So what we've got is a 1/3 of Erin 'winning', 1/3 of Thomas 'winning' and a 1/3 chance of a tie which leaves Erin ahead. So she's got a 2/3 chance of being first.
Additionally (but not in any consequential fashion), generating a random number between 1 and 100 (inclusive) gives you 100 possibilities (duh). With three outcomes:
100 / 3 = 33.333333333333336
The first option has slightly more chance to be picked. If Erin wanted to be fair(er), she'd multiply by 99.Here's a Python solution showing it's not just JS:
link: http://paste.ubuntu.com/23222240/
results:
{
'Erin Ptacek': 6523,
'Thomas Ptacek': 1951,
'Jeremy Rauch': 1526
}
(with apologies to
ShaneWilton, I've completely rewritten this comment so the following comments are out of date)