Skip to content

PickN(slice, number) and Shuffle(slice) generators#89

Merged
untoldwind merged 1 commit intoleanovate:masterfrom
Bastes:master
Apr 11, 2026
Merged

PickN(slice, number) and Shuffle(slice) generators#89
untoldwind merged 1 commit intoleanovate:masterfrom
Bastes:master

Conversation

@Bastes
Copy link
Copy Markdown
Contributor

@Bastes Bastes commented Apr 9, 2026

This adds 2 new generators:

  • PickN(slice, number) generates a new slice of randomly-selected number (up to len(slice)) items from (slice) in the same order with no duplicates
  • Shuffle(slice) generates a new slice with all items from slice in random order

Tests 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

@Bastes
Copy link
Copy Markdown
Contributor Author

Bastes commented Apr 9, 2026

(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)

@Bastes
Copy link
Copy Markdown
Contributor Author

Bastes commented Apr 9, 2026

(there, added tests for determinism + reworked both generators to use the built-in rng over re-using other generators)

@untoldwind
Copy link
Copy Markdown
Collaborator

Unluckly my current work related projects do not involve go, so it is hard to keep track of all the changes.
I updated the min version to 1.20.

@untoldwind untoldwind merged commit 87e05ea into leanovate:master Apr 11, 2026
0 of 3 checks passed
@Bastes
Copy link
Copy Markdown
Contributor Author

Bastes commented Apr 11, 2026

Well, you're quite reactive as far as I'm concerned ;) thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants