kotlin-statistics v1.1.3 Release Notes

Release Date: 2018-07-11 // over 3 years ago
  • 🚀 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> or Sequence<T>.

    • randomFirst() - Selects one random element but throws an error if no elements are found.
    • randomFirstOrNull() - Selects one random element but returns null if no elements are found.
    • random(n: Int) - Selects n random elements.
    • randomDistinct(n: Int) - Select n distinct random elements.

    Also available are WeightedCoin and WeightedDice utilities which can be helpful to assign probabilities to discrete true/false or T 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) }