Skip to content

support random sampling of tuple types#35856

Closed
stev47 wants to merge 1 commit intoJuliaLang:masterfrom
stev47:feature/random-tuple-type
Closed

support random sampling of tuple types#35856
stev47 wants to merge 1 commit intoJuliaLang:masterfrom
stev47:feature/random-tuple-type

Conversation

@stev47
Copy link
Copy Markdown
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 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 stev47 force-pushed the feature/random-tuple-type branch from 4c62bc0 to 9bd9afa Compare December 2, 2020 11:16
@stev47
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

stev47 commented Dec 8, 2020

buildbot failures seem unrelated (network errors)

@rfourquet
Copy link
Copy Markdown
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
Copy Markdown
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 <stephan@ecshi.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

randomness Random number generation and the Random stdlib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants