Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/odds/ext/rand.rb

Instance Method Summary collapse

Instance Method Details

#rand_numObject



2
3
4
5
# File 'lib/odds/ext/rand.rb', line 2

def rand_num
  num = rand * (self.end.to_f - self.begin.to_f)
  num + self.begin.to_f
end

#rand_sq_numObject



7
8
9
10
11
12
# File 'lib/odds/ext/rand.rb', line 7

def rand_sq_num
  a = self.begin**2
  b = self.end**2
  num = (a..b).rand_num
  num.to_f**0.5
end

#rand_sqrt_numObject



14
15
16
17
18
19
# File 'lib/odds/ext/rand.rb', line 14

def rand_sqrt_num
  a = self.begin.to_f**0.5
  b = self.end.to_f**0.5
  num = (a..b).rand_num
  num.to_f**2
end