Nice post. Be aware that shuffling an Array like this is not perfectly random and a proper implementation is a little more complicated: medium.com/@nitinpatel_20236/how-t...
Very interesting, I hadn't considered how using sort like that could end up with an infinite loop!
sort
In case anyone is interested, I plotted the distributions for the Math.random() - 0.5 and the Fisher-Yates shuffles.
Math.random() - 0.5
That's 100000 shuffles of abcd for each algorithm.
abcd
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice post. Be aware that shuffling an Array like this is not perfectly random and a proper implementation is a little more complicated: medium.com/@nitinpatel_20236/how-t...
Very interesting, I hadn't considered how using
sort
like that could end up with an infinite loop!In case anyone is interested, I plotted the distributions for the
Math.random() - 0.5
and the Fisher-Yates shuffles.That's 100000 shuffles of
abcd
for each algorithm.