kudzu-forest / elm-random-pool / RandomPool

Types


type RandomPool a

Represents pooled data which can be randomly chosen. The data are devided into two parts, named pump and pond. Contents in pump are already chosen but not yet used. Contents in pond are yet to be chosen. This division is for implementing behavior like "the same thing never happens continuously".

Creation

singleton : a -> RandomPool a

Creates new randompool with only one element in the pond and empty pump.

fromList : ( Basics.Float, a ) -> List ( Basics.Float, a ) -> RandomPool a

Creates new randompool with all the element in the list poured into pond and empty pump.

Addition

insertWithRelativeWeight : Basics.Float -> a -> RandomPool a -> RandomPool a

Pour one new element into the pond. The first parameter is the relative weight of the added element. Relative weight of 1 means that the new element has the same weight as the total of all other elements in the pond.

insertListWithRelativeWeight : List ( Basics.Float, a ) -> RandomPool a -> RandomPool a

Inserts arbitrary number of elements into the pond. The first component of parameter list content is relative weight. (1 means total weight before any of them are inserted.)

Random Operation

suck : RandomPool a -> Random.Generator (RandomPool a)

Random generator that generates RandomePool which consists of pump with one more element randomly chosen from the pond and pond with that element removed.

suckFor : Basics.Int -> RandomPool a -> Random.Generator (RandomPool a)

suck for arbitrary times.

cycle : Basics.Float -> RandomPool a -> Random.Generator ( a, RandomPool a )

Get one new element from the pond into pump, and changes the weight of the head and release it to the pond.

Pump Operation

get : RandomPool a -> Maybe a

Returns the head(the oldest element) of pump.

discard : RandomPool a -> RandomPool a

Removes the head of pump. Nothing occurs if the pump is empty.

Query

count : RandomPool a -> Basics.Int

Returnes how many contents in the pool.

totalWeight : RandomPool a -> WideFloat

Returnes the sum of weight in the pool represented as WideFloat.