public class RouletteSelector extends Object
Simulates selection based on a roulette wheel where all items have a weight expressing the size of their section of the wheel. The size of the wheel is the sum of all item weights. During selection a random number in (0, wheel size) is picked and then the item corresponding to this section of the wheel is selected.
For a set of items with equal weight they will all have the same probability of being selected. Items which are assigned higher weights will have a higher likelihood of being selected (and the opposite holds for lower weights).
|Constructor and Description|
|Modifier and Type||Method and Description|
Select an item from a given list by roulette selection, where each item has a weight expressing the size of its section of the roulette wheel.
E- type of items
items- items from which one is to be selected
weights- item weights (same order as items)
random- random generator (cannot be
nullif all weights are zero or the item list is empty
IllegalArgumentException- if both lists are not of the same size or if any of the given weights is < 0
Copyright © 2016. All rights reserved.