https://github.com/todesking/weighted_sample
Enumerable#weighted_sample_by
https://github.com/todesking/weighted_sample
Last synced: about 1 year ago
JSON representation
Enumerable#weighted_sample_by
- Host: GitHub
- URL: https://github.com/todesking/weighted_sample
- Owner: todesking
- License: mit
- Created: 2012-08-21T03:40:48.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2019-12-13T21:12:27.000Z (over 6 years ago)
- Last Synced: 2025-04-23T03:17:20.654Z (about 1 year ago)
- Language: Ruby
- Size: 93.8 KB
- Stars: 13
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# weighted_sample
This gem add Enumerable#weighted_sample_by mehtod.
## Installation
Add this line to your application's Gemfile:
gem 'weighted_sample'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weighted_sample
## Usage
[1, 9].weighted_sample_by {|x| x}
=> 9(90%) or 1(10%)
### Restrictions
* Weight is zero or positive Integer(Negative or Float is not allowed).
* Sum of weights should > 0
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request