-
Notifications
You must be signed in to change notification settings - Fork 52
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
Introduce shuffleList
and shuffleListM
#140
Conversation
5ce327f
to
33e4226
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
In general +1 but I have few comments. What are stability guarantees for the shuffle? Do we promise to change algorithm output only on major updates? BiasShuffle is very slightly biased. For example let look at shuffle of Analysis for n-element list is more complicated. Probability of having at least one collision in indices is subject to birthday paradox. So maybe it's possible to detect bias with 32-bit Ints. And yes Fisher-Yates shuffle is unbiased, has O(n) complexity but requires in-place mutation. It's awfully inconvenient to not having access to proper arrays P.S. I'm not sure that |
That's precisely why I didn't bother writing it using mutable arrays. I don't think this issue alone warrants a dependency on
Yes. That would be the case. I would rather not change the underlying semantics on non-breaking version updates. |
I'm on a fence about this. Arrays are after all very basic functionality. It's first time we run into algorithm that requires arrays. Will it be another one? Something that requires lookup tables, such as |
If you like pain, you can use naked |
I'd rather use my own redefinition of |
33e4226
to
4d212cc
Compare
uniformList
, shuffleList
and shuffleListM
shuffleList
and shuffleListM
As it was described in #139 this PR implements the most basic version of random list shuffling, both stateful and pure implementations.
The way the shuffling is achieved is somewhat similar to the implementation in QuickCheck. There are better ways, but the one that I know of requires a mutable array, which would make a dependency footprint or implementation quite a bit more complicated.
We can experiment with performance and quality of alternative implementations for random-1.3, whenever that will come. Unless someone is willing to provide a better implementation (with some becnhmarks) soon enough as a PR into this branch, I think current implementation is sufficiently good enough for the initial version.
Changes in this PR are non-breaking, so I'll happily backport them into a minor
random-1.2.2
release.As a nice extra this PR also contains a pure implementation of
uniformList