chance

A Crystal port of the Ruby probability library called Chance

Chance

This is a Crystal port of the Ruby Chance library

Chance is a library for exploring uncertainty in code. Maybe you always wanted to program with probability, to be boldly indecisive, to roll the dice without scratching your head? That's what we're all about here.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  chance:
    github: kingsleyh/chance
  1. Run shards install

Usage

require "chance"

Chance Case Statements

Chance Cases take any number of args, each one being a probability statement with an outcome block attached. The probabilities must add to 100 percent (sorry, for once in your life you will have to give less than 110%). Only one outcome will be evaluated, as you would expect:

outcome = Chance.case(
  Chance(String).new(70.percent).will {"snow"},
  Chance(String).new(20.percent).will {"sleet"},
  Chance(String).new(8.percent).will  {"sun"},
  Chance(String).new(1.percent).will  {"knives"}
)

Contributing

  1. Fork it (https://github.com/kingsleyh/chance/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

chance

Owner
Statistic
  • 0
  • 1
  • 0
  • 0
  • 0
  • almost 6 years ago
  • February 5, 2019
License

MIT License

Links
Synced at

Sun, 22 Dec 2024 10:08:48 GMT

Languages