fixed bug in breaking ties.  was not uniformly random