Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getUrnIdx(urns::Array, D::Int64, N::Int64)
- group = zeros(Int64, 0)
- while length(group) != D
- idx = rand(1:N)
- if !in(idx, group)
- push!(group, idx)
- end
- end
- values = zeros(Int64, length(group))
- for i in 1:length(group)
- values[i] = urns[group[i]]
- end
- minIdx = indmin(values)
- min = values[minIdx]
- indices = zeros(Int64, 0)
- push!(indices, group[minIdx])
- splice!(values, minIdx)
- splice!(group, minIdx)
- while length(values) > 0 && min == values[indmin(values)]
- push!(indices, group[minIdx])
- splice!(values, minIdx)
- splice!(group, minIdx)
- end
- urnIdx = indices[1]
- if length(indices) > 1
- urnIdx = rand(1:length(indices))
- end
- return urnIdx
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement