Class: Array::SampleRandom
Instance Method Summary collapse
-
#initialize(rng) ⇒ SampleRandom
constructor
A new instance of SampleRandom.
- #rand(size) ⇒ Object
Constructor Details
#initialize(rng) ⇒ SampleRandom
Returns a new instance of SampleRandom
1747 1748 1749 |
# File 'opal/opal/corelib/array.rb', line 1747 def initialize(rng) @rng = rng end |
Instance Method Details
#rand(size) ⇒ Object
1751 1752 1753 1754 1755 1756 1757 |
# File 'opal/opal/corelib/array.rb', line 1751 def rand(size) random = Opal.coerce_to @rng.rand(size), Integer, :to_int raise RangeError, 'random value must be >= 0' if `random < 0` raise RangeError, 'random value must be less than Array size' unless `random < size` random end |