kotlin-statistics v1.2.1 Release Notes
Release Date: 2018-12-27 // over 6 years ago-
0️⃣ Made some fixes to the
binByComparable()
implementation so ends are not exclusive by default.
Previous changes from v1.1.3
-
🚀 This release contains some practical features for randomness and weighted probabilities.
Kotlin-Statistics now has a few helpful extensions to randomly sample elements from an
Iterable<T>
orSequence<T>
.randomFirst()
- Selects one random element but throws an error if no elements are found.randomFirstOrNull()
- Selects one random element but returnsnull
if no elements are found.random(n: Int)
- Selectsn
random elements.randomDistinct(n: Int)
- Selectn
distinct random elements.
Also available are
WeightedCoin
andWeightedDice
utilities which can be helpful to assign probabilities to discretetrue
/false
orT
outcomes. This can be helpful for games, stochastic programming, simulation, and optimization.enum class Move { ATTACK, DEFEND, HEAL, RETREAT}fun main(args: Array\<String\>) { val gameDice = WeightedDice( Move.ATTACK to .60, Move.DEFEND to .20, Move.HEAL to .10, Move.RETREAT to .10 ) val nextMove = gameDice.roll() println(nextMove) }