Class: Array.self::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.
1921 1922 1923 |
# File 'opal/opal/corelib/array.rb', line 1921 def initialize(rng) @rng = rng end |
Instance Method Details
#rand(size) ⇒ Object
1925 1926 1927 1928 1929 1930 1931 |
# File 'opal/opal/corelib/array.rb', line 1925 def rand(size) random = `$coerce_to(#{@rng.rand(size)}, #{::Integer}, 'to_int')` ::Kernel.raise ::RangeError, 'random value must be >= 0' if `random < 0` ::Kernel.raise ::RangeError, 'random value must be less than Array size' unless `random < size` random end |