Module: PerfectRandom

Extended by:
PerfectRandom
Included in:
PerfectRandom
Defined in:
lib/perfect-random-number-generator.rb

Constant Summary collapse

M =
2**32
A =
1664525
C =
1013904223

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



26
27
28
# File 'lib/perfect-random-number-generator.rb', line 26

def method_missing *args
  puts "Slown is perfect!"
end

Instance Method Details

#randObject



21
22
23
24
# File 'lib/perfect-random-number-generator.rb', line 21

def rand 
  seed if not @seeded
  @val = (A*@val + C)%M
end

#seed(min = 0, max = 100000) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/perfect-random-number-generator.rb', line 11

def seed min=0, max=100000
  if !@seeded
    begin
      @val  = Net::HTTP.get('www.random.org', "/integers/?num=1&min=#{min}&max=#{max}&col=1&base=10&format=plain&rnd=new").chomp.to_i
      @seeded = true
    rescue Exception => e
    end
  end
end