Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The article itself is quite useful, but a warning on the sort tutorial he links to (http://www.javascriptkit.com/javatutors/arraysort.shtml). Contrary to what it says, you cannot reliably shuffle a list by doing:

  myarray.sort(function() {return 0.5 - Math.random()})
This just makes every comparison return a random value, which may or may not produce particularly random results, depending on the sort algorithm. It's exactly the bug that bit Microsoft in their not-very-random browser shuffle screen.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: