Skip to content

Commit

Permalink
Allow to add the scale for the normal distribution
Browse files Browse the repository at this point in the history
When generating floats using the normal distribution, allow to specify
the scale. This allow us to decide how close or far away should be the
generated points from the limit/key point.

Contributes to rantly-rb#29

Pair-programmed by @Ana06 and @vicgalle.
  • Loading branch information
vicgalle authored and Ana06 committed Dec 20, 2017
1 parent dd4d00a commit 3f62b62
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/rantly/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ def positive_integer
range(0)
end

def float(distribution=nil, center=0)
def float(distribution=nil, params={})
case distribution
when :normal
params[:center] ||= 0
params[:scale] || = 1
raise "The distribution scale should be greater than zero" unless params[:scale].positive?
# Sum of 6 draws from a uniform distribution give as a draw of a normal
# distribution centered in 3
[rand, rand, rand, rand, rand, rand].sum - 3 + center
([rand, rand, rand, rand, rand, rand].sum - 3) * params[:scale] + center
else
rand
end
Expand Down

0 comments on commit 3f62b62

Please sign in to comment.