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
- Add the dependency to your
shard.yml
:
dependencies:
chance:
github: kingsleyh/chance
- 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
- Fork it (https://github.com/kingsleyh/chance/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Kingsley Hendrickse - creator and maintainer
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