RandSum

generate random numbers that sum up to a given integer

Package Installation

git clone [email protected]:computalya/rand_sum.git
cd rand_sum
gem install rand_sum

Installation

Add this line to your application's Gemfile:

gem 'rand_sum'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rand_sum

Usage

examples 1

400.rand_sum(2)
# => [153, 247]

example 2

result = 400.rand_sum(2)
puts "#{result} sum => #{result.inject(:+)}"
# => "[346, 54] sum => 400"

other examples

1000.rand_sum(5)
# => [691, 32, 104, 164, 9] => 1000

100.rand_sum(0)
# => 100

100.rand_sum(1)
# => 100

in irb

require 'rand_sum'
# => true

100.rand_sum(5)
# => [22, 76, 2]

License

The gem is available as open source under the terms of the MIT License.

Development Notes

Adding new tags

git tag -a v0.1.0 -m 'rand_sum-0.1.0'
git push --tags all

running tests

rake test

# or
ruby test/test_rand_sum.rb -v