Class: Simpack::LCG
- Inherits:
-
Object
- Object
- Simpack::LCG
- Defined in:
- lib/simpack.rb
Instance Attribute Summary collapse
-
#increment ⇒ Object
readonly
Returns the value of attribute increment.
-
#modulus ⇒ Object
readonly
Returns the value of attribute modulus.
-
#multiplier ⇒ Object
readonly
Returns the value of attribute multiplier.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ LCG
constructor
A new instance of LCG.
- #uniform(n = 1) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ LCG
Returns a new instance of LCG.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/simpack.rb', line 9 def initialize( = {}) = {multiplier: 6364136223846793005, modulus: 2 ** 64, increment: 1442695040888963407, seed: Time.now.to_i} = .merge() () @multiplier = [:multiplier] @modulus = [:modulus] @increment = [:increment] @seed = @x = [:seed] end |
Instance Attribute Details
#increment ⇒ Object (readonly)
Returns the value of attribute increment.
7 8 9 |
# File 'lib/simpack.rb', line 7 def increment @increment end |
#modulus ⇒ Object (readonly)
Returns the value of attribute modulus.
7 8 9 |
# File 'lib/simpack.rb', line 7 def modulus @modulus end |
#multiplier ⇒ Object (readonly)
Returns the value of attribute multiplier.
7 8 9 |
# File 'lib/simpack.rb', line 7 def multiplier @multiplier end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
7 8 9 |
# File 'lib/simpack.rb', line 7 def seed @seed end |
Instance Method Details
#uniform(n = 1) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/simpack.rb', line 24 def uniform(n = 1) return generate_number if n == 1 results = Array.new(n) (0...n).each do |i| results[i] = generate_number end results end |