-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shuffle isn't correct #14
Comments
Maybe this is correct
|
Actually, you would swap 0 with nextInt(1) which is also 0, so there is no need, for sure. |
Ah true. But yea you can skip going down to index 0 as the swap would always be with itself. Thanks for the interesting read at codinghorr niyaznigmatullin. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This algorithm doesn't shuffle it correctly, not every permutation is equiprobable. You have to do:
to fix it.
More information:
https://blog.codinghorror.com/the-danger-of-naivete/
The text was updated successfully, but these errors were encountered: