Sha256: be464fef5967618d9af50e352b3d0e25a78c72e5c7e13fb960b4feb9896bdfd4
Contents?: true
Size: 643 Bytes
Versions: 21
Compression:
Stored size: 643 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 (rand()*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
21 entries across 21 versions & 1 rubygems