Class: RailsDataExplorer::Statistics::RngPowerLaw
- Inherits:
-
Object
- Object
- RailsDataExplorer::Statistics::RngPowerLaw
- Defined in:
- lib/rails_data_explorer/statistics/rng_power_law.rb
Overview
Responsibilities:
* Provide random numeric data, following a power distribution.
Instance Method Summary collapse
-
#initialize(min = 1, max = 1000, pow = 2, rng = lambda { Kernel.rand }) ⇒ RngPowerLaw
constructor
A new instance of RngPowerLaw.
-
#rand ⇒ Object
Returns random data following a power distribution.
Constructor Details
#initialize(min = 1, max = 1000, pow = 2, rng = lambda { Kernel.rand }) ⇒ RngPowerLaw
Returns a new instance of RngPowerLaw.
15 16 17 18 |
# File 'lib/rails_data_explorer/statistics/rng_power_law.rb', line 15 def initialize(min = 1, max = 1000, pow = 2, rng = lambda { Kernel.rand }) @min, @max, @pow, @rng = min, max, pow, rng @max += 1 end |
Instance Method Details
#rand ⇒ Object
Returns random data following a power distribution.
21 22 23 24 25 26 27 28 |
# File 'lib/rails_data_explorer/statistics/rng_power_law.rb', line 21 def rand y = ( ( (@max ** (@pow + 1) - @min ** (@pow + 1)) * @rng.call + @min ** (@pow + 1) ) ** (1.0 / (@pow + 1)) ).to_i (@max - 1 - y) + @min end |