@Nullable
    @Override
    public T pick() {
        if (allEntries.isEmpty()) {
            return null;
        }

        final ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
        lock.lock();
        try {
            long target = threadLocalRandom.nextLong(remaining);
            final Iterator<CandidateContext<T>> it = currentEntries.iterator();
            while (it.hasNext()) {
                final CandidateContext<T> entry = it.next();
                final int weight = entry.weight();
                target -= weight;
                if (target < 0) {
                    entry.increment();
                    if (entry.isFull()) {
                        it.remove();
                        entry.reset();
                        remaining -= weight;
                        if (remaining == 0) {
                            // As all entries are full, reset `currentEntries` and `remaining`.
                            currentEntries.addAll(allEntries);
                            remaining = total;
                        } else {
                            assert remaining > 0 : remaining;
                        }
                    }
                    return entry.get();
                }
            }
        } finally {
            lock.unlock();
        }

        // Since `allEntries` is not empty, should subselect one Endpoint from `allEntries`.
        throw new Error("Should never reach here");
    }
This {@link LoadBalancer} selects an element using random and {@link WeightedObject#weight()}.
If there are A(weight 10), B(weight 4) and C(weight 6) elements, the chances that
elements are selected are 10/20, 4/20 and 6/20, respectively. If A is selected 10 times and B and C are not
selected as much as their weight, then A is removed temporarily and the chances that B and C are selected are
4/10 and 6/10.
core/src/main/java/com/linecorp/armeria/common/loadbalancer/WeightedRandomLoadBalancer.java