Class: Croupier::Distributions::Uniform
Overview
Uniform Distribution Continous distribution where all points in an interval have the same probability.
Instance Attribute Summary
#description, #name, #parameters
Class Method Summary
collapse
Instance Method Summary
collapse
#configure, #generate_sample
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(options={})
@name = "Uniform distribution"
@description = "Continuous distribution on [a,b] (defaults to [0,1]) where all points in the interval are equally likely"
configure(options)
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.cli_options
{: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, :b => 1}
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 @parameters[:b] < @parameters[:a]
rand Range.new(@parameters[:a], @parameters[:b])
end
|