Class: Croupier::Distributions::Uniform
- Inherits:
-
Croupier::Distribution
- Object
- Croupier::Distribution
- Croupier::Distributions::Uniform
- Defined in:
- lib/croupier/distributions/uniform.rb
Overview
Uniform Distribution Continous distribution where all points in an interval have the same probability.
Instance Attribute Summary
Attributes inherited from Croupier::Distribution
#description, #name, #parameters
Class Method Summary collapse
Instance Method Summary collapse
- #default_parameters ⇒ Object
- #generate_number ⇒ Object
-
#initialize(options = {}) ⇒ Uniform
constructor
A new instance of Uniform.
Methods inherited from Croupier::Distribution
#configure, #generate_sample, #params
Constructor Details
#initialize(options = {}) ⇒ Uniform
Returns a new instance of Uniform.
11 12 13 14 15 |
# File 'lib/croupier/distributions/uniform.rb', line 11 def initialize(={}) @name = "Uniform distribution" @description = "Continuous distribution on [a,b] (defaults to [0,1]) where all points in the interval are equally likely" configure() end |
Class Method Details
.cli_name ⇒ Object
26 27 28 |
# File 'lib/croupier/distributions/uniform.rb', line 26 def self.cli_name "uniform" end |
.cli_options ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/croupier/distributions/uniform.rb', line 30 def self. {:options => [ [:a, 'interval start value', {:type=>:float, :default => 0.0}], [:b, 'interval end value', {:type=>:float, :default => 1.0}] ], :banner => "Uniform distribution. Generate numbers following a continuous distribution on [a,b] (defaults to [0,1]) where all points in the interval are equally likely" } end |
Instance Method Details
#default_parameters ⇒ Object
22 23 24 |
# File 'lib/croupier/distributions/uniform.rb', line 22 def default_parameters {:a => 0.0, :b => 1.0} end |
#generate_number ⇒ Object
17 18 19 20 |
# File 'lib/croupier/distributions/uniform.rb', line 17 def generate_number raise Croupier::InputParamsError, "Invalid interval values" if params[:b] < params[:a] rand Range.new(params[:a], params[:b]) end |