0.19
No commit activity in last 3 years
No release in over 3 years
Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
~> 2.0.1
~> 3.12
 Project Readme

simple-random Build status

Generate random numbers sampled from the following distributions:

  • Beta
  • Cauchy
  • Chi square
  • Dirichlet
  • Exponential
  • Gamma
  • Inverse gamma
  • Laplace (double exponential)
  • Normal
  • Student t
  • Triangular
  • Uniform
  • Weibull

Based on John D. Cook's SimpleRNG C# library.

Installation

Plain Ruby

Run gem install simple-random in your terminal.

Ruby on Rails

Add gem 'simple-random', '~> 1.0.0' to your Gemfile and run bundle install.

Usage

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.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, but please do not mess with the gemspec, Rakefile, VERSION, LICENSE, or .travis.yml. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request.

HT: This list was modified from the default instructions that ship with jeweler.

Copyright

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).

History

1.0.3 - 2015-11-25

  • Attempt to reduce code complexity and improve readability
  • Change error handling somewhat to throw specific errors and improve messages

1.0.2 - 2015-11-24

  • Merge pull request from cunchem to fix Laplace method

1.0.1 - 2015-07-31

  • Merge purcell's changes to fix numeric seeds

1.0.0 - 2014-07-08

  • Migrate to new version of Jeweler for gem packaging
  • Merge jwroblewski's changes into a new multi-threaded simple random class
  • Change from Code Project Open License to CDDL-1.0

0.10.0 - 2014-03-31

0.9.3 - 2011-09-16

  • Sample from Dirichlet distribution with given set of parameters

0.9.2 - 2011-09-06

  • Use microseconds for random seed

0.9.1 - 2010-07-27

  • First stable release