PickN(slice, number) and Shuffle(slice) generators#89
Merged
untoldwind merged 1 commit intoleanovate:masterfrom Apr 11, 2026
Merged
PickN(slice, number) and Shuffle(slice) generators#89untoldwind merged 1 commit intoleanovate:masterfrom
untoldwind merged 1 commit intoleanovate:masterfrom
Conversation
Contributor
Author
|
(after a bit more thinking, I'm about to add tests for both generators that validate the same seed and input results in the same generation) |
Contributor
Author
|
(there, added tests for determinism + reworked both generators to use the built-in rng over re-using other generators) |
Collaborator
|
Unluckly my current work related projects do not involve go, so it is hard to keep track of all the changes. |
Contributor
Author
|
Well, you're quite reactive as far as I'm concerned ;) thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds 2 new generators:
PickN(slice, number)generates a new slice of randomly-selectednumber(up tolen(slice)) items from (slice) in the same order with no duplicatesShuffle(slice)generates a new slice with all items fromslicein random orderTests inspired by the existing generators'.
Neither generators have shrinker, as explained in their godoc, as the shrinking strategy is not obvious and the generators are intended to work on small slices.
Originally designed for go 1.22 and retrofitted to work with go 1.12