Class: LFSR::Base
- Inherits:
-
Object
- Object
- LFSR::Base
- Defined in:
- lib/lfsr.rb
Direct Known Subclasses
Pure::Size10, Pure::Size11, Pure::Size12, Pure::Size13, Pure::Size14, Pure::Size15, Pure::Size16, Pure::Size17, Pure::Size18, Pure::Size19, Pure::Size2, Pure::Size20, Pure::Size21, Pure::Size22, Pure::Size23, Pure::Size24, Pure::Size25, Pure::Size26, Pure::Size27, Pure::Size28, Pure::Size29, Pure::Size3, Pure::Size30, Pure::Size31, Pure::Size32, Pure::Size33, Pure::Size34, Pure::Size35, Pure::Size36, Pure::Size37, Pure::Size38, Pure::Size39, Pure::Size4, Pure::Size40, Pure::Size41, Pure::Size42, Pure::Size43, Pure::Size44, Pure::Size45, Pure::Size46, Pure::Size47, Pure::Size48, Pure::Size49, Pure::Size5, Pure::Size50, Pure::Size51, Pure::Size52, Pure::Size53, Pure::Size54, Pure::Size55, Pure::Size56, Pure::Size57, Pure::Size58, Pure::Size59, Pure::Size6, Pure::Size60, Pure::Size61, Pure::Size7, Pure::Size8, Pure::Size9
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
-
#reg ⇒ Object
(also: #peek)
readonly
Returns the value of attribute reg.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
Instance Method Summary collapse
-
#initialize(max = nil, seed = nil) ⇒ Base
constructor
A new instance of Base.
- #reset(new_seed) ⇒ Object
Constructor Details
#initialize(max = nil, seed = nil) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 17 |
# File 'lib/lfsr.rb', line 9 def initialize(max = nil, seed = nil) # The C code depends on this being the first ivar to work properly. @reg = 1 # This should be the second variable. @max = (max || self.class.const_get(:MASK) - 1) + 1 reset seed end |
Instance Attribute Details
#max ⇒ Object
Returns the value of attribute max.
6 7 8 |
# File 'lib/lfsr.rb', line 6 def max @max end |
#reg ⇒ Object (readonly) Also known as: peek
Returns the value of attribute reg.
5 6 7 |
# File 'lib/lfsr.rb', line 5 def reg @reg end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
7 8 9 |
# File 'lib/lfsr.rb', line 7 def seed @seed end |
Instance Method Details
#reset(new_seed) ⇒ Object
19 20 21 22 23 |
# File 'lib/lfsr.rb', line 19 def reset(new_seed) @reg = @seed = (new_seed || Time.now.utc.to_i) & self.class.const_get(:MASK) raise ArgumentError, "The seed #{new_seed} is unacceptable for this register size" if new_seed && @reg == 0 @reg = @seed = (new_seed || Time.now.utc.to_i) & self.class.const_get(:MASK) while @reg == 0 end |