@@ -222,12 +222,13 @@ cdef class RandomState:
222222"be instantized." )
223223self ._bitgen = (< bitgen_t * > PyCapsule_GetPointer (capsule ,name ))[0 ]
224224self ._aug_state .bit_generator = & self ._bitgen
225- self ._reset_gauss ()
226225self .lock = bit_generator .lock
226+ self ._reset_gauss ()
227227
228228cdef _reset_gauss (self ):
229- self ._aug_state .has_gauss = 0
230- self ._aug_state .gauss = 0.0
229+ with self .lock :
230+ self ._aug_state .has_gauss = 0
231+ self ._aug_state .gauss = 0.0
231232
232233def seed (self ,seed = None ):
233234"""
@@ -301,8 +302,9 @@ cdef class RandomState:
301302'MT19937 BitGenerator. To silence this warning, '
302303'set `legacy` to False.' ,RuntimeWarning )
303304legacy = False
304- st ['has_gauss' ]= self ._aug_state .has_gauss
305- st ['gauss' ]= self ._aug_state .gauss
305+ with self .lock :
306+ st ['has_gauss' ]= self ._aug_state .has_gauss
307+ st ['gauss' ]= self ._aug_state .gauss
306308if legacy and not isinstance (self ._bit_generator ,_MT19937 ):
307309raise ValueError (
308310"legacy can only be True when the underlying bitgenerator is "