11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
3-
43"""
5- Copyright (c) 2016-2020 Philippe Schmouker, schmouk (at) typee.ovh
4+ Copyright (c) 2016-2021 Philippe Schmouker, schmouk (at) typee.ovh
65
76Permission is hereby granted, free of charge, to any person obtaining a copy
87of this software and associated documentation files (the "Software"), to deal
2625#=============================================================================
2726from .baserandom import BaseRandom
2827from .fastrand32 import FastRand32
28+ from .types import SeedStateType , StateType
2929
3030
3131#=============================================================================
3232class BaseMRG ( BaseRandom ):
33- """
34- Definition of the base class for all MRG pseudo-random generators.
33+ """Definition of the base class for all MRG pseudo-random generators.
34+
3535 This module is part of library PyRandLib.
3636
37- Copyright (c) 2016-2020 Philippe Schmouker
37+ Copyright (c) 2016-2021 Philippe Schmouker
3838
3939 Multiple Recursive Generators (MRGs) uses recurrence to evaluate pseudo-random
4040 numbers suites. Recurrence is of the form:
@@ -89,10 +89,10 @@ class BaseMRG( BaseRandom ):
8989 should definitively pass.
9090 """
9191
92- #======================================================================== =
93- def __init__ (self , _seedState : ( int , float , list ) = None ) -> None :
94- """
95- Constructor.
92+ #------------------------------------------------------------------------ =
93+ def __init__ (self , _seedState : SeedStateType = None ) -> None :
94+ """Constructor.
95+
9696 _seedState is either a valid state, an integer, a float or None.
9797 About valid state: this is a tuple containing a list of
9898 self._LIST_SIZE integers and an index in this list (index value
@@ -109,31 +109,32 @@ def __init__(self, _seedState: (int,float,list) = None) -> None:
109109 # since it internally calls self.setstate().
110110
111111
112- #======================================================================== =
112+ #------------------------------------------------------------------------ =
113113 def random (self ) -> float :
114- """
115- This is the core of the pseudo-random generator.
114+ """This is the core of the pseudo-random generator.
115+
116116 Returned values are within [0.0, 1.0).
117117 Inheriting classes HAVE TO IMPLEMENT this method - see MRGRand287
118118 for an example.
119119 """
120- raise NotImplementedError
120+ raise NotImplementedError ()
121121
122122
123- #======================================================================== =
124- def getstate (self ) -> tuple :
125- """
126- Return an object capturing the current internal state of the generator.
123+ #------------------------------------------------------------------------ =
124+ def getstate (self ) -> StateType :
125+ """Returns an object capturing the current internal state of the generator.
126+
127127 This object can be passed to setstate() to restore the state. It is a
128128 tuple containing a list of self._LIST_SIZE integers and an
129129 index in this list (index value being then in range(0,self._LIST_SIZE).
130130 """
131131 return (self ._list [:], self ._index )
132132
133133
134- #=========================================================================
135- def setstate (self , _seedState : tuple ) -> None :
136- """
134+ #------------------------------------------------------------------------=
135+ def setstate (self , _seedState : StateType ) -> None :
136+ """Restores the internal state of the generator.
137+
137138 _seedState should have been obtained from a previous call to
138139 getstate(), and setstate() restores the internal state of the
139140 generator to what it was at the time setstate() was called.
@@ -159,20 +160,20 @@ def setstate(self, _seedState: tuple) -> None:
159160 self ._list = _seedState [0 ][:]
160161
161162
162- #======================================================================== =
163+ #------------------------------------------------------------------------ =
163164 def _initIndex (self , _index : int ) -> None :
164- """
165- Inits the internal index pointing to the internal list.
165+ """Inits the internal index pointing to the internal list.
166166 """
167167 try :
168168 self ._index = int ( _index ) % self ._LIST_SIZE
169169 except :
170170 self ._index = 0
171171
172172
173- #=========================================================================
174- def _initList (self , _initialSeed : list = None ) -> None :
175- """
173+ #------------------------------------------------------------------------=
174+ def _initList (self , _initialSeed : StateType = None ) -> None :
175+ """Inits the internal list of values.
176+
176177 Inits the internal list of values according to some initial
177178 seed that has to be an integer or a float ranging within
178179 [0.0, 1.0). Should it be None or anything else then the
0 commit comments