Class: Crypt::Xorshift64Star
- Inherits:
-
Object
- Object
- Crypt::Xorshift64Star
- Defined in:
- lib/crypt/isaac/xorshift/pure.rb,
ext/crypt/isaac/xorshift/xorshift.c
Constant Summary collapse
- UINT32_C =
2**32
- UINT64_C =
2**64
- UINT64_Cf =
UINT64_C.to_f
Instance Method Summary collapse
- #==(v) ⇒ Object
-
#initialize(args) ⇒ Xorshift64Star
constructor
A new instance of Xorshift64Star.
- #new_seed ⇒ Object
- #rand(args) ⇒ Object
- #seed ⇒ Object
- #srand(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ Xorshift64Star
Returns a new instance of Xorshift64Star.
21 22 23 24 25 |
# File 'ext/crypt/isaac/xorshift/xorshift.c', line 21 def initialize( seed = new_seed ) @seed = nil srand( seed ) @old_seed = seed end |
Instance Method Details
#==(v) ⇒ Object
106 107 108 |
# File 'ext/crypt/isaac/xorshift/xorshift.c', line 106 def ==(v) self.class == v.class && @old_seed == v.seed end |
#new_seed ⇒ Object
40 41 42 43 44 45 |
# File 'ext/crypt/isaac/xorshift/xorshift.c', line 40 def new_seed n = Time.now @@counter ||= 0 @@counter += 1 [n.usec % 65536, n.to_i % 65536, $$ ^ 65536, @@counter % 65536 ].collect {|x| x.to_s(16)}.join.to_i(16) end |
#rand(args) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'ext/crypt/isaac/xorshift/xorshift.c', line 77 def rand( n = 0) @seed ^= @seed >> 12 @seed ^= @seed << 25 @seed ^= @seed >> 27 if n < 1 ( ( @seed * 2685821657736338717 ) % UINT64_C ) / UINT64_Cf else ( ( @seed * 2685821657736338717 ) % UINT64_C ) % Integer( n ) end end |
#seed ⇒ Object
102 103 104 |
# File 'ext/crypt/isaac/xorshift/xorshift.c', line 102 def seed @old_seed end |
#srand(args) ⇒ Object
58 59 60 61 |
# File 'ext/crypt/isaac/xorshift/xorshift.c', line 58 def srand( seed = new_seed ) @old_seed = @seed @seed = seed % UINT64_C end |