This file contains 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
import Base: start, next, done, eltype, length, size | |
immutable SelfPairs | |
xs | |
n::Int | |
end | |
eltype(it::SelfPairs) = eltype(it.xs) | |
length(it::SelfPairs) = binomial(it.n,2) |
This file contains 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
import Base: GLOBAL_RNG, rand, isslotfilled | |
function rand(rng::AbstractRNG, d::Dict) | |
isempty(d) && throw(ArugmentError("dictionary must be non-empty")) | |
n = length(d.keys) | |
while true | |
i = rand(rng,1:n) | |
!isdefined(d.keys,i) && continue | |
return d.keys[i],d.vals[i] | |
end | |
end |