@Test public void testRandomPick() { DistributedList<String> set = prepareTwoElementSet(); String firstValue = set.pickRandomly(mockOfRandom(0.0D)); String otherFirstValue = set.pickRandomly(mockOfRandom(0.24D)); String secondValue = set.pickRandomly(mockOfRandom(0.25D)); String otherSecondValue = set.pickRandomly(mockOfRandom(0.49D)); String thirdValue = set.pickRandomly(mockOfRandom(0.5D)); String otherThirdValue = set.pickRandomly(mockOfRandom(0.74D)); String fourthValue = set.pickRandomly(mockOfRandom(0.75D)); String otherFourthValue = set.pickRandomly(mockOfRandom(0.99D)); assertEquals(firstValue, otherFirstValue); assertEquals(secondValue, otherSecondValue); assertEquals(thirdValue, otherThirdValue); assertEquals(fourthValue, otherFourthValue); }
public T pickRandomly(RandomNumberGenerator random) { return getElementFromCumulativeDistribution(1.0D - random.nextDouble(0.0D, 1.0D)); }
DistributedList { public T pickRandomly(RandomNumberGenerator random) { return getElementFromCumulativeDistribution(1.0D - random.nextDouble(0.0D, 1.0D)); } }
DistributedList { public T pickRandomly(RandomNumberGenerator random) { return getElementFromCumulativeDistribution(1.0D - random.nextDouble(0.0D, 1.0D)); } DistributedList(final List<WeightedElement<T>> underlyingWeights); }
DistributedList { public T pickRandomly(RandomNumberGenerator random) { return getElementFromCumulativeDistribution(1.0D - random.nextDouble(0.0D, 1.0D)); } DistributedList(final List<WeightedElement<T>> underlyingWeights); static DistributedList<T> singleton(final T element); static DistributedList<T> weightedOrDefault(final Collection<T> underlyingSet); static DistributedList<T> uniform(final Collection<T> underlyingSet); @SuppressWarnings("unchecked") static DistributedList<T> empty(); List<WeightedElement<T>> distributedList(); T pickRandomly(RandomNumberGenerator random); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Stream<T> stream(); List<T> list(); boolean isEmpty(); }
DistributedList { public T pickRandomly(RandomNumberGenerator random) { return getElementFromCumulativeDistribution(1.0D - random.nextDouble(0.0D, 1.0D)); } DistributedList(final List<WeightedElement<T>> underlyingWeights); static DistributedList<T> singleton(final T element); static DistributedList<T> weightedOrDefault(final Collection<T> underlyingSet); static DistributedList<T> uniform(final Collection<T> underlyingSet); @SuppressWarnings("unchecked") static DistributedList<T> empty(); List<WeightedElement<T>> distributedList(); T pickRandomly(RandomNumberGenerator random); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Stream<T> stream(); List<T> list(); boolean isEmpty();  }