Simple random number generator gem for Ruby (based on C# code by John D. Cook).
Generate random numbers sampled from the following distributions:
Based on John D. Cook’s SimpleRNG C# library.
Run gem install simple-random
in your terminal.
Add gem 'simple-random', '~> 1.0.0'
to your Gemfile and run bundle install
.
Some of the methods available:
> r = SimpleRandom.new # Initialize a SimpleRandom instance
=> #<SimpleRandom:0x007f9e3ad58010 @m_w=521288629, @m_z=362436069>
> r.set_seed # By default the same random seed is used, so we change it
> r.uniform(0, 5) # Produce a uniform random sample from the open interval (lower, upper).
=> 0.6353204359766096
> r.normal(1000, 200) # Sample normal distribution with given mean and standard deviation
=> 862.5447157384566
> r.exponential(2) # Get exponential random sample with specified mean
=> 0.9386480625062965
> r.triangular(0, 2.5, 10) # Get triangular random sample with specified lower limit, mode, upper limit
=> 3.1083306054169277
Note that by default the same seed is used every time to generate the random numbers. This means that repeated runs should yield the same results. If you would like it to always initialize with a different seed, or if you are using multiple SimpleRandom objects, you should call #set_seed
on the instance.
See lib/simple-random.rb for all available methods and options.
Rakefile
, VERSION
, LICENSE
, or .travis.yml
.HT: This list was modified from the default instructions that ship with jeweler.
Distributed under the Code Project Open License, which is similar to MIT or BSD. See LICENSE for full details (don’t just take my word for it that it’s similar to those licenses).