Comment by neckro23
11 years ago
It's not mentioned by name in the article, but the "proper" way to do it is with a Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
Depending on the array implentation, adding and removing elements is often an O(n) operation, which isn't terribly efficient. The Fisher-Yates method lets you get the same results without messing with the array length.
No comments yet
Contribute on Hacker News ↗