Project

newcomb

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Generate random numbers that adhere to Benford's Law
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 13
 Project Readme

Newcomb

Generate random numbers that adhere to Benford's Law

Made by laserlemon Gem version Build status

Usage

Newcomb works very much like Kernel.rand or SecureRandom.random_number. In order to fetch a random float between 0 (inclusive) and 1 (exclusive):

Newcomb.random_number # => 0.49552091973604767

To fetch a random positive integer, provide the upper (exclusive) limit:

Newcomb.random_number(100) # => 16

To fetch a random positive float, provide the upper (exclusive) limit as a float:

Newcomb.random_number(100.0) # => 21.895884449446473

To fetch a random integer within a range, provide a range with integer endpoints:

Newcomb.random_number(100..1000) # => 141

To fetch a random float within a range, provide a range with float (or mixed) endpoints:

Newcomb.random_number(100.0..1000.0) # => 203.90587157406662
Newcomb.random_number(100..1000.0) # => 424.9768102233391
Newcomb.random_number(100.0..1000) # => 628.7978615329862

Over a sufficiently large sample size, the distribution of Newcomb's random numbers will demonstrate Benford's Law.

History

While Benford's Law is named after American scientist Frank Benford, the principle was original discovered by Simon Newcomb over fifty years earlier. In addition to his numerous accomplishments in mathematics and astronomy, Newcomb had a fantastic beard.

Exhibit A