3 ms·
The output of Math.random also doesn't seem to be very uniform. With the original code, I'm consistently seeing Erin appear first 60% of the time, and Thomas fi
by ShaneWilton 10y ago
The output of Math.random also doesn't seem to be very uniform. With the original code, I'm consistently seeing Erin appear first 60% of the time, and Thomas first 30% of the time. Jeremy is left with 10%.
Even after changing the code to multiply by 99 instead of 100, the results don't change very much at all.
- RKoutnik 10y agoInteresting, running just the number generation under node v6.5.0 gives: { '0': 340364, '1': 330093, '-1': 329543 } So we see a slight bias for zero (elements are equal) there. ~Lemme try it in Chrome and get back to you.~ AHA, repro'd in Chrome latest: http://jsbin.com/cefuqi/edit?js,console http://jsbin.com/cefuqi/edit?js,console Also repros in node. Fascinating. There goes my afternoon...
- ShaneWilton 10y agoHa, I was starting to think I was crazy.
- thethirdone 10y agoThe problem is in the sort function. It expects the comparison to be deterministic and thus does not give the fully randomized list. Instead giving each name a distinct value (between 0 and 1) and sort based on those values.
- RKoutnik 10y agoPosting this to trigger HNReplies - See my first comment response to you for the full story.