2424
2525#=============================================================================
2626from .baserandom import BaseRandom
27- from .fastrand63 import FastRand63
27+ from .fastrand32 import FastRand32
2828from .types import SeedStateType , StateType
2929
3030
@@ -59,7 +59,7 @@ class BaseLFib64( BaseRandom ):
5959 See LFib78, LFib116, LFib668 and LFib1340 for long period LFib generators (resp.
6060 2^78, 2^116, 2^668 and 2^1340 periods, i.e. resp. 3.0e+23, 8.3e+34, 1.2e+201 and
6161 2.4e+403 periods) while same computation time and far higher precision (64-bits
62- calculations) then MRGs, but memory consumption (resp. 17, 55, 607 and 1279
62+ calculations) than MRGs, but more memory consumption (resp. 17, 55, 607 and 1279
6363 integers).
6464
6565 Please notice that this class and all its inheriting sub-classes are callable.
@@ -151,17 +151,24 @@ def setstate(self, _seedState: StateType) -> None:
151151 (e.g. None) then the shuffling of the local current time
152152 value is used as such an initial seed.
153153 """
154- if not isinstance ( _seedState , tuple ):
155- self ._initIndex ( 0 )
156- self ._initList ( _seedState )
154+ try :
155+ count = len ( _seedState )
157156
158- elif len ( _seedState ) < 2 :
157+ if count == 0 :
158+ self ._initIndex ( 0 )
159+ self ._initList ()
160+
161+ elif count == 1 :
162+ self ._initIndex ( 0 )
163+ self ._initList ( _seedState [0 ] )
164+
165+ else :
166+ self ._initIndex ( _seedState [1 ] )
167+ self ._list = _seedState [0 ][:]
168+
169+ except :
159170 self ._initIndex ( 0 )
160- self ._initList ( _seedState [0 ] )
161-
162- else :
163- self ._initIndex ( _seedState [1 ] )
164- self ._list = _seedState [0 ][:]
171+ self ._initList ( _seedState )
165172
166173
167174 #------------------------------------------------------------------------=
@@ -183,15 +190,8 @@ def _initList(self, _initialSeed: StateType = None) -> None:
183190 [0.0, 1.0). Should it be None or anything else then the
184191 current local time value is used as initial seed value.
185192 """
186- myRand = FastRand63 ( _initialSeed )
187- #-----------------------------------------------------------------
188- def _getValue ( _dummy ):
189- myRand ()
190- v = myRand ._value << 1
191- return v + (1 if myRand () >= 0.5 else 0 )
192- #-----------------------------------------------------------------
193- self ._list = list ( map ( _getValue , range (self ._LIST_SIZE ) ) )
193+ myRand = FastRand32 ( _initialSeed )
194+ self ._list = [ (int (myRand (0x1_0000_0000 )) << 32 ) + int (myRand (0x1_0000_0000 )) for _ in range (self ._LIST_SIZE ) ]
194195
195-
196196#===== end of module baselfib64.py =====================================
197197
0 commit comments