Class: Capricious::MWC5
- Inherits:
-
Object
- Object
- Capricious::MWC5
- Defined in:
- lib/capricious/mwc5.rb
Instance Attribute Summary collapse
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#seeds ⇒ Object
readonly
Returns the value of attribute seeds.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(seed = nil) ⇒ MWC5
constructor
A new instance of MWC5.
- #next_f ⇒ Object
- #next_i ⇒ Object
- #reset(seed = nil) ⇒ Object
Constructor Details
#initialize(seed = nil) ⇒ MWC5
Returns a new instance of MWC5.
29 30 31 |
# File 'lib/capricious/mwc5.rb', line 29 def initialize(seed=nil) reset(seed) end |
Instance Attribute Details
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
24 25 26 |
# File 'lib/capricious/mwc5.rb', line 24 def seed @seed end |
#seeds ⇒ Object (readonly)
Returns the value of attribute seeds.
24 25 26 |
# File 'lib/capricious/mwc5.rb', line 24 def seeds @seeds end |
Class Method Details
Instance Method Details
#next_f ⇒ Object
54 55 56 |
# File 'lib/capricious/mwc5.rb', line 54 def next_f next_i.quo(0xffffffff.to_f) end |
#next_i ⇒ Object
50 51 52 |
# File 'lib/capricious/mwc5.rb', line 50 def next_i shift_ks end |
#reset(seed = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/capricious/mwc5.rb', line 33 def reset(seed=nil) @seed ||= (seed || Time.now.utc.to_i) unless @seeds seeder = LFSR.new_with_seed(@seed) @seeds = [seeder.next_i & 0xffffffff] 4.times do 9.times do # the observed lag-10 autocorrelation of the LFSRs is low seeder.next_i end @seeds << (seeder.next_i & 0xffffffff) end end @x,@y,@z,@w,@v = @seeds end |