E - 元素类型public class WeightListRandomSelector<E> extends Object implements Selector<E>, Serializable
WeightObj依次增加权重,随机时根据权重计算随机值,然后二分查找小于等于随机值的权重,返回对应的元素。
[obj1, obj2, obj3, obj4 ]
[----, -----, - , ------]
然后最后一个元素的权重值为总权重值,即obj2的权重值为obj1权重+obj2本身权重,依次类推。| Constructor and Description |
|---|
WeightListRandomSelector()
构造
|
WeightListRandomSelector(int poolSize)
构造
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(E e,
int weight)
增加随机种子
|
boolean |
isEmpty()
判断是否为空
|
boolean |
remove(E e)
移除随机种子
|
E |
select()
选择下一个对象
|
public WeightListRandomSelector()
public WeightListRandomSelector(int poolSize)
poolSize - 初始随机池大小Copyright © 2025. All rights reserved.