Skip to content

Generate random numbers that adhere to Benford's Law

License

Notifications You must be signed in to change notification settings

laserlemon/newcomb

Repository files navigation

Newcomb

Generate random numbers that adhere to Benford's Law

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

About

Generate random numbers that adhere to Benford's Law

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published