Skip to content

API reference / @jsprismarine/entity-brains / ShufflingList

Class: ShufflingList<Item> ​

Defined in: behavior/gate.ts:21

Java's ShufflingList: a weighted list that reorders in place.

The draw is the exponential ranking trick Java uses: each entry takes the key -random ** (1 / weight) and the list sorts ascending, which makes the probability that a given entry sorts first proportional to its weight.

Type Parameters ​

Item ​

Item

Constructors ​

Constructor ​

new ShufflingList<Item>(): ShufflingList<Item>

Returns ​

ShufflingList<Item>

Methods ​

add() ​

add(item, weight): this

Defined in: behavior/gate.ts:25

Appends an entry and returns the list, so entries chain. A higher weight sorts first more often.

Parameters ​

item ​

Item

weight ​

number

Returns ​

this


items() ​

items(): readonly Item[]

Defined in: behavior/gate.ts:40

The entries in their current order, without their weights.

Returns ​

readonly Item[]


shuffle() ​

shuffle(random): this

Defined in: behavior/gate.ts:31

Redraws every entry's key and reorders the list in place.

Parameters ​

random ​

() => number

Returns ​

this