chance
Version, currently 0.1.01 version
- 0.1.0latestFeb 6, 2019
github.com/kingsleyh/chance
A Crystal port of the Ruby probability library called Chance
Installation
# Add this to your shard.yml
dependencies:
chance:
github: kingsleyh/chance
version: ~> 0.1.0Then run:
shards installshard.yml
- Crystal
0.27.0- License
- MIT
- Author
- Kingsley Hendrickse
Dependencies
This version declares no dependencies.
README
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
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Feb 6, 2019
- Commit
a1dea84ecc36- Crystal
0.27.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/kingsleyh/chance
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1