>Top

RandomFloat

Ruby library to generate Float random number sequence.

Download

README

RandomFloat generates Float random number sequence.

Usage:

rndf = RandomFloat.new  #=>  <instance of RandomFloat>
rndf.rand  #=>  <random number of Float>
rndf.rand  #=>  <random number of Float>
rndf.rand  #=>  <random number of Float>

legends
(a, b)  --  open interval
[a, b]  --  closed interval

rndf = RandomFloat.new                           # default generates [-Float::MAX, Float::MAX]
rndf = RandomFloat.new :gt => 1, :lt => 2        # generates (1, 2)
rndf = RandomFloat.new :gt_or_eq => 1, :lt => 2  # generates [1, 2)
rndf = RandomFloat.new :gt => 1, :lt_or_eq => 2  # generates (1, 2]
rndf = RandomFloat.new :gt_or_eq => -Float::INFINITY, :lt_or_eq => Float::INFINITY
                                                 # generates [-Float::INFINITY, Float::INFINITY]
rndf = RandomFloat.new :gt_or_eq => Float::MIN   # generates any positive normalized float number

NOTE

(1) Interval arguments value considered as an instance of Float. If you
    specified ":gt_or_eq => 0.3", because 0.3 cannot exactly represented
    by Float, 0.29999999999999999 could generate.

(2) RandomFloat identified plus zero or minus zero. If you specify ":lt => 0",
    -0.0 could generate.

(3) The distribution follows its of floating-point number. For example, if
    the interval is [0, 1], generates many very small values. This may be
    counterintuitive.

(4) If the interval contains (near) 0, RandomFloat generates denormalized
    numbers. The absolute value of these are less than Float::MIN .