Skip to content

Commit

Permalink
Create rand function for Base.KeySet and Base.ValueIterator{Dict} (#5…
Browse files Browse the repository at this point in the history
…1608)

Fixes #51605 . 

I also created a version of rand for `Base.ValueIterator{Dict}` which
currently throws an error.
  • Loading branch information
Tortar authored Oct 9, 2023
1 parent f4e1a15 commit 4115c72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stdlib/Random/src/generation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ function rand(rng::AbstractRNG, sp::SamplerSimple{<:Dict,<:Sampler})
end
end

rand(rng::AbstractRNG, sp::SamplerTrivial{<:Base.KeySet{<:Any,<:Dict}}) =
rand(rng, sp[].dict).first

rand(rng::AbstractRNG, sp::SamplerTrivial{<:Base.ValueIterator{<:Dict}}) =
rand(rng, sp[].dict).second

## random values from Set

Sampler(::Type{RNG}, t::Set{T}, n::Repetition) where {RNG<:AbstractRNG,T} =
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Random/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()], [Xoshiro()])
randset => Int,
GenericSet(randset) => Int,
randdict => Pair{Int,Int},
keys(randdict) => Int,
values(randdict) => Int,
GenericDict(randdict) => Pair{Int,Int},
1:100 => Int,
rand(Int, 100) => Int,
Expand Down

2 comments on commit 4115c72

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.