Class: RuneRb::Core::RubyISAAC
- Inherits:
-
Object
- Object
- RuneRb::Core::RubyISAAC
- Defined in:
- lib/rune/core/ruby_isaac.rb
Overview
An implementation of an ISAAC cipher used to generate random numbers for message interchange.
Instance Method Summary collapse
-
#initialize(seed) ⇒ RubyISAAC
constructor
Called when a new ISAAC Cipher is created.
-
#next_value ⇒ Object
Gets the next random value.
Constructor Details
#initialize(seed) ⇒ RubyISAAC
Called when a new ISAAC Cipher is created.
7 8 9 10 11 12 13 14 15 |
# File 'lib/rune/core/ruby_isaac.rb', line 7 def initialize(seed) @aa = 0 @bb = 0 @cc = 0 @mm = [] @randrsl = Array.new(256, 0) seed.each_with_index { |element, i| @randrsl[i] = element } randinit end |
Instance Method Details
#next_value ⇒ Object
Gets the next random value. If 256 cycles have occurred, the results array is regenerated.
19 20 21 22 23 24 25 26 |
# File 'lib/rune/core/ruby_isaac.rb', line 19 def next_value if @randcnt.zero? isaac @randcnt = 256 end @randcnt -= 1 @randrsl[@randcnt].int end |