Class: Keisan::Functions::Rand
- Inherits:
-
ProcFunction
- Object
- Keisan::Function
- ProcFunction
- Keisan::Functions::Rand
- Defined in:
- lib/keisan/functions/rand.rb
Instance Attribute Summary
Attributes inherited from ProcFunction
Attributes inherited from Keisan::Function
Instance Method Summary collapse
-
#call(context, *args) ⇒ Object
Single argument: integer in range [0, max) Double argument: integer in range [min, max).
-
#initialize ⇒ Rand
constructor
A new instance of Rand.
Methods inherited from ProcFunction
Methods inherited from Keisan::Function
#differentiate, #evaluate, #simplify, #value
Constructor Details
#initialize ⇒ Rand
Returns a new instance of Rand.
4 5 6 7 |
# File 'lib/keisan/functions/rand.rb', line 4 def initialize @name = "rand" @arity = ::Range.new(1,2) end |
Instance Method Details
#call(context, *args) ⇒ Object
Single argument: integer in range [0, max) Double argument: integer in range [min, max)
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/keisan/functions/rand.rb', line 11 def call(context, *args) case args.size when 1 context.random.rand(args.first) when 2 context.random.rand(args.first...args.last) else raise Exceptions::InvalidFunctionError.new end end |