Skip to content
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

support random sampling of tuple types #35856

Closed
wants to merge 1 commit into from

Conversation

stev47
Copy link
Contributor

@stev47 stev47 commented May 12, 2020

This allows e.g rand(NTuple{5,Int}) to sample a tuple of 5 Ints.

The implementation simply assembles a tuple by calling rand on the
corresponding type parameters of the tuple type.
A generated function is used to ensure type stability.

Note that this is distinct from rand(::Tuple) to select a random element from a tuple.

@rfourquet rfourquet added the domain:randomness Random number generation and the Random stdlib label May 12, 2020
@tkf tkf mentioned this pull request Jul 8, 2020
18 tasks
This allows e.g `rand(NTuple{5,Int})` to sample a tuple of 5 `Int`s.

The implementation simply assembles a tuple by calling `rand` on the
corresponding type parameters of the tuple type.
A generated function is used to ensure type stability.
@stev47
Copy link
Contributor Author

stev47 commented Dec 2, 2020

Rebased and added news entry.
Can we take a look at this for 1.6? @rfourquet @StefanKarpinski

@stev47
Copy link
Contributor Author

stev47 commented Dec 8, 2020

buildbot failures seem unrelated (network errors)

@rfourquet
Copy link
Member

I will have a closer look tentatively this week, but this won't make it for 1.6. In the meantime, the functionality can be found in RandomExtensions :) This means I personally definitely support this feature, but given that this package is not yet very popular, I suspect people are not dying for this functionality...

@rfourquet
Copy link
Member

Sorry for forgetting about this; the functionality was added in #50251, but I rebased this in #51630 to merge the tests, which caught the fact that we didn't support rand(Tuple{}). Thanks!

@rfourquet rfourquet closed this Oct 7, 2023
rfourquet added a commit that referenced this pull request Oct 7, 2023
This is a rebase of #35856, where we keep only the tests, as the
functionality was added in #50251. This also adds the possibility to
call `rand` on an empty tuple type: `rand(Tuple{})`.

Co-authored-by: Stephan Hilb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants