Sha256: 20bb9c1330eb80f0e252c342699c071143558cbb4a96fbc1a1975a8130ecfca8

Contents?: true

Size: 649 Bytes

Versions: 12

Compression:

Stored size: 649 Bytes

Contents

class Numeric

  #
  # +rrand(upper = 0)+: random number generator
  #
  # returns a random number in the range receiver-upper bound
  # 
  # If any of the numbers (the receiver +or+ the argument) are +Float+s
  # the method will return a +Float+. If both arguments are integers then an
  # +Integer+ will be returned.
  #
  # (this method is present in the SuperCollider sclang interpreter)
  #
  #:nodoc:

  def rrand(upper = 0.0)
    lobound = self.to_f
    rng = upper.to_f - lobound

    (Mext::PRNG.r*rng) + lobound
  end

end

class Integer

  def rrand(upper = 0)
    res = super(upper)
    upper.is_a?(Integer) ? res.round : res
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby-mext-0.21.6 lib/mext/numeric/rrand.rb
ruby-mext-0.21.5 lib/mext/numeric/rrand.rb
ruby-mext-0.21.4 lib/mext/numeric/rrand.rb
ruby-mext-0.21.3 lib/mext/numeric/rrand.rb
ruby-mext-0.21.2 lib/mext/numeric/rrand.rb
ruby-mext-0.21.1 lib/mext/numeric/rrand.rb
ruby-mext-0.21.0 lib/mext/numeric/rrand.rb
ruby-mext-0.20.1 lib/mext/numeric/rrand.rb
ruby-mext-0.20.0 lib/mext/numeric/rrand.rb
ruby-mext-0.19.0 lib/mext/numeric/rrand.rb
ruby-mext-0.18.3 lib/mext/numeric/rrand.rb
ruby-mext-0.18.2 lib/mext/numeric/rrand.rb