Class: Keisan::Functions::Rand

Inherits:
Keisan::Function show all
Defined in:
lib/keisan/functions/rand.rb

Instance Attribute Summary

Attributes inherited from Keisan::Function

#name

Instance Method Summary collapse

Constructor Details

#initializeRand

Returns a new instance of Rand.



4
5
6
# File 'lib/keisan/functions/rand.rb', line 4

def initialize
  @name = "rand"
end

Instance Method Details

#call(context, *args) ⇒ Object

Single argument: integer in range [0, max) Double argument: integer in range [min, max)



10
11
12
13
14
15
16
17
18
19
# File 'lib/keisan/functions/rand.rb', line 10

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 Keisan::Exceptions::InvalidFunctionError.new
  end
end