Code example for Random

Methods: nextDoublenextInt

	 * Retrieves an item with probability proportional to its weight in the 
	 * {@code Map} provided in the input. 
	public T nextItem() 
		ItemPair item_pair = item_pairs.get(random.nextInt(item_pairs.size()));
		if (random.nextDouble() < item_pair.weight)
			return item_pair.light;
		return item_pair.heavy;
	 * Manages light object/heavy object/light conditional probability tuples. 
	private class ItemPair  
		T light;
		T heavy;
		double weight;
Experience pair programming with AI  Get Codota for Java