Skip to content

Commit 8096218

Browse files
committed
#54-rename _LIST_SIZE to _STATE_SIZE
Completed. Validated.
1 parent 93b39a2 commit 8096218

14 files changed

Lines changed: 64 additions & 64 deletions

PyRandLib/baselfib64.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class BaseLFib64( BaseRandom ):
7070
print( rand(a) ) # prints a pseudo-random value within [0.0, a)
7171
print( rand(a,b) ) # prints a pseudo-random value within [a , b)
7272
73-
Inheriting classes have to define class attribute '_LIST_SIZE'. See LFib78 for an
73+
Inheriting classes have to define class attribute '_STATE_SIZE'. See LFib78 for an
7474
example.
7575
7676
Reminder:
@@ -99,10 +99,10 @@ def __init__(self, _seedState: SeedStateType = None) -> None:
9999
100100
_seedState is either a valid state, an integer, a float or None.
101101
About valid state: this is a tuple containing a list of
102-
self._LIST_SIZE integers and an index in this list (index value
103-
being then in range (0,self._LIST_SIZE)). Should _seedState be
102+
self._STATE_SIZE integers and an index in this list (index value
103+
being then in range (0,self._STATE_SIZE)). Should _seedState be
104104
a sole integer or float then it is used as initial seed for
105-
the random filling of the internal list of self._LIST_SIZE
105+
the random filling of the internal list of self._STATE_SIZE
106106
integers. Should _seedState be anything else (e.g. None) then
107107
the shuffling of the local current time value is used as such an
108108
initial seed.
@@ -129,8 +129,8 @@ def getstate(self) -> StateType:
129129
"""Returns an object capturing the current internal state of the generator.
130130
131131
This object can be passed to setstate() to restore the state. It is a
132-
tuple containing a list of self._LIST_SIZE integers and an
133-
index in this list (index value being then in range(0,self._LIST_SIZE).
132+
tuple containing a list of self._STATE_SIZE integers and an
133+
index in this list (index value being then in range(0,self._STATE_SIZE).
134134
"""
135135
return (self._state[:], self._index)
136136

@@ -143,11 +143,11 @@ def setstate(self, _seedState: StateType) -> None:
143143
getstate(), and setstate() restores the internal state of the
144144
generator to what it was at the time setstate() was called.
145145
About valid state: this is a tuple containing a list of
146-
self._LIST_SIZE integers (31-bits) and an index in this list
147-
(index value being then in range(0,self._LIST_SIZE)). Should
146+
self._STATE_SIZE integers (31-bits) and an index in this list
147+
(index value being then in range(0,self._STATE_SIZE)). Should
148148
_seedState be a sole integer or float then it is used as
149149
initial seed for the random filling of the internal list of
150-
self._LIST_SIZE integers. Should _seedState be anything else
150+
self._STATE_SIZE integers. Should _seedState be anything else
151151
(e.g. None) then the shuffling of the local current time
152152
value is used as such an initial seed.
153153
"""
@@ -176,7 +176,7 @@ def _initIndex(self, _index: int) -> None:
176176
"""Inits the internal index pointing to the internal list.
177177
"""
178178
try:
179-
self._index = int( _index ) % self._LIST_SIZE
179+
self._index = int( _index ) % self._STATE_SIZE
180180
except:
181181
self._index = 0
182182

@@ -191,7 +191,7 @@ def _initState(self, _initialSeed: StateType = None) -> None:
191191
current local time value is used as initial seed value.
192192
"""
193193
myRand = FastRand32( _initialSeed )
194-
self._state = [ (int(myRand(0x1_0000_0000)) << 32) + int(myRand(0x1_0000_0000)) for _ in range(self._LIST_SIZE) ]
194+
self._state = [ (int(myRand(0x1_0000_0000)) << 32) + int(myRand(0x1_0000_0000)) for _ in range(self._STATE_SIZE) ]
195195

196196
#===== end of module baselfib64.py =====================================
197197

PyRandLib/basemrg.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BaseMRG( BaseRandom ):
6565
print( rand(a) ) # prints a pseudo-random value within [0.0, a)
6666
print( rand(a,b) ) # prints a pseudo-random value within [a , b)
6767
68-
Inheriting classes have to define class attributes '_LIST_SIZE' and '_MODULO'. See
68+
Inheriting classes have to define class attributes '_STATE_SIZE' and '_MODULO'. See
6969
MRGRand287 for an example.
7070
7171
Reminder:
@@ -93,10 +93,10 @@ def __init__(self, _seedState: SeedStateType = None) -> None:
9393
9494
_seedState is either a valid state, an integer, a float or None.
9595
About valid state: this is a tuple containing a list of
96-
self._LIST_SIZE integers and an index in this list (index value
97-
being then in range(0,self._LIST_SIZE)). Should _seedState be
96+
self._STATE_SIZE integers and an index in this list (index value
97+
being then in range(0,self._STATE_SIZE)). Should _seedState be
9898
a sole integer or float then it is used as initial seed for
99-
the random filling of the internal list of self._LIST_SIZE
99+
the random filling of the internal list of self._STATE_SIZE
100100
integers. Should _seedState be anything else (e.g. None) then
101101
the shuffling of the local current time value is used as such an
102102
initial seed.
@@ -123,8 +123,8 @@ def getstate(self) -> StateType:
123123
"""Returns an object capturing the current internal state of the generator.
124124
125125
This object can be passed to setstate() to restore the state. It is a
126-
tuple containing a list of self._LIST_SIZE integers and an
127-
index in this list (index value being then in range(0,self._LIST_SIZE).
126+
tuple containing a list of self._STATE_SIZE integers and an
127+
index in this list (index value being then in range(0,self._STATE_SIZE).
128128
"""
129129
return (self._state[:], self._index)
130130

@@ -137,11 +137,11 @@ def setstate(self, _seedState: StateType) -> None:
137137
getstate(), and setstate() restores the internal state of the
138138
generator to what it was at the time setstate() was called.
139139
About valid state: this is a tuple containing a list of
140-
self._LIST_SIZE integers (31-bits) and an index in this list
141-
(index value being then in range(0,self._LIST_SIZE)). Should
140+
self._STATE_SIZE integers (31-bits) and an index in this list
141+
(index value being then in range(0,self._STATE_SIZE)). Should
142142
_seedState be a sole integer or float then it is used as
143143
initial seed for the random filling of the internal list of
144-
self._LIST_SIZE integers. Should _seedState be anything else
144+
self._STATE_SIZE integers. Should _seedState be anything else
145145
(e.g. None) then the shuffling of the local current time
146146
value is used as such an initial seed.
147147
"""
@@ -170,7 +170,7 @@ def _initIndex(self, _index: int) -> None:
170170
"""Inits the internal index pointing to the internal list.
171171
"""
172172
try:
173-
self._index = int( _index ) % self._LIST_SIZE
173+
self._index = int( _index ) % self._STATE_SIZE
174174
except:
175175
self._index = 0
176176

@@ -186,7 +186,7 @@ def _initState(self, _initialSeed: StateType = None) -> None:
186186
"""
187187
# feeds the list according to an initial seed and the value+1 of the modulo.
188188
myRand = FastRand32( _initialSeed )
189-
self._state = [ int(myRand(self._MODULO+1)) for _ in range(self._LIST_SIZE) ]
189+
self._state = [ int(myRand(self._MODULO+1)) for _ in range(self._STATE_SIZE) ]
190190

191191

192192
#===== end of module basemrg.py ========================================

PyRandLib/basewell.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BaseWELL( BaseRandom ):
7373
print( rand(a) ) # prints a pseudo-random value within [0.0, a)
7474
print( rand(a,b) ) # prints a pseudo-random value within [a , b)
7575
76-
Inheriting classes have to define class attributes '_LIST_SIZE'. See Well512a for
76+
Inheriting classes have to define class attributes '_STATE_SIZE'. See Well512a for
7777
an example.
7878
7979
Reminder:
@@ -105,10 +105,10 @@ def __init__(self, _seedState: SeedStateType = None) -> None:
105105
106106
_seedState is either a valid state, an integer, a float or None.
107107
About valid state: this is a tuple containing a list of
108-
self._LIST_SIZE integers and an index in this list (index value
109-
being then in range(0,self._LIST_SIZE)). Should _seedState be
108+
self._STATE_SIZE integers and an index in this list (index value
109+
being then in range(0,self._STATE_SIZE)). Should _seedState be
110110
a sole integer or float then it is used as initial seed for
111-
the random filling of the internal list of self._LIST_SIZE
111+
the random filling of the internal list of self._STATE_SIZE
112112
integers. Should _seedState be anything else (e.g. None) then
113113
the shuffling of the local current time value is used as such an
114114
initial seed.
@@ -135,8 +135,8 @@ def getstate(self) -> StateType:
135135
"""Returns an object capturing the current internal state of the generator.
136136
137137
This object can be passed to setstate() to restore the state. It is a
138-
tuple containing a list of self._LIST_SIZE integers and an index in this
139-
list (index value being then in range(0,self._LIST_SIZE).
138+
tuple containing a list of self._STATE_SIZE integers and an index in this
139+
list (index value being then in range(0,self._STATE_SIZE).
140140
"""
141141
return (self._state[:], self._index)
142142

@@ -149,11 +149,11 @@ def setstate(self, _seedState: StateType) -> None:
149149
getstate(), and setstate() restores the internal state of the
150150
generator to what it was at the time setstate() was called.
151151
About valid state: this is a tuple containing a list of
152-
self._LIST_SIZE integers (32-bits) and an index in this list
153-
(index value being then in range(0,self._LIST_SIZE)). Should
152+
self._STATE_SIZE integers (32-bits) and an index in this list
153+
(index value being then in range(0,self._STATE_SIZE)). Should
154154
_seedState be a sole integer or float then it is used as
155155
initial seed for the random filling of the internal list of
156-
self._LIST_SIZE integers. Should _seedState be anything else
156+
self._STATE_SIZE integers. Should _seedState be anything else
157157
(e.g. None) then the shuffling of the local current time
158158
value is used as such an initial seed.
159159
"""
@@ -182,7 +182,7 @@ def _initIndex(self, _index: int) -> None:
182182
"""Inits the internal index pointing to the internal list.
183183
"""
184184
try:
185-
self._index = int( _index ) % self._LIST_SIZE
185+
self._index = int( _index ) % self._STATE_SIZE
186186
except:
187187
self._index = 0
188188

@@ -198,7 +198,7 @@ def _initState(self, _initialSeed: StateType = None) -> None:
198198
"""
199199
# feeds the list according to an initial seed and the value+1 of the modulo.
200200
myRand = FastRand32( _initialSeed )
201-
self._state = [ int(myRand(0x1_0000_0000)) for _ in range(self._LIST_SIZE) ]
201+
self._state = [ int(myRand(0x1_0000_0000)) for _ in range(self._STATE_SIZE) ]
202202

203203

204204
#-------------------------------------------------------------------------

PyRandLib/lfib116.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class LFib116( BaseLFib64 ):
109109

110110
#-------------------------------------------------------------------------
111111
# 'protected' constant
112-
_LIST_SIZE = 55 # this 'LFib(2^64, 55, 24, +)' generator is based on a suite containing 55 integers
112+
_STATE_SIZE = 55 # this 'LFib(2^64, 55, 24, +)' generator is based on a suite containing 55 integers
113113

114114

115115
#-------------------------------------------------------------------------
@@ -121,14 +121,14 @@ def random(self) -> float:
121121
# evaluates indexes in suite for the i-24 and i-55 -th values
122122
k24 = self._index-24
123123
if k24 < 0:
124-
k24 += LFib116._LIST_SIZE
124+
k24 += LFib116._STATE_SIZE
125125

126126
# then evaluates current value
127127
myValue = (self._state[k24] + self._state[self._index]) & 0xffff_ffff_ffff_ffff
128128
self._state[self._index] = myValue
129129

130130
# next index
131-
self._index = (self._index+1) % LFib116._LIST_SIZE
131+
self._index = (self._index+1) % LFib116._STATE_SIZE
132132

133133
# then returns float value within [0.0, 1.0)
134134
return myValue * 5.421_010_862_427_522_170_037_3e-20 # / 18_446_744_073_709_551_616.0

PyRandLib/lfib1340.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class LFib1340( BaseLFib64 ):
110110

111111
#-------------------------------------------------------------------------
112112
# 'protected' constant
113-
_LIST_SIZE = 1279 # this 'LFib(2^64, 1279, 861, +)' generator is based on a suite containing 1279 integers
113+
_STATE_SIZE = 1279 # this 'LFib(2^64, 1279, 861, +)' generator is based on a suite containing 1279 integers
114114

115115

116116
#-------------------------------------------------------------------------
@@ -122,14 +122,14 @@ def random(self) -> float:
122122
# evaluates indexes in suite for the i-861 and i-1279 -th values
123123
k861 = self._index-861
124124
if k861 < 0:
125-
k861 += LFib1340._LIST_SIZE
125+
k861 += LFib1340._STATE_SIZE
126126

127127
# then evaluates current value
128128
myValue = (self._state[k861] + self._state[self._index]) & 0xffff_ffff_ffff_ffff
129129
self._state[self._index] = myValue
130130

131131
# next index
132-
self._index = (self._index+1) % LFib1340._LIST_SIZE
132+
self._index = (self._index+1) % LFib1340._STATE_SIZE
133133

134134
# then returns float value within [0.0, 1.0)
135135
return myValue * 5.421_010_862_427_522_170_037_3e-20 # / 18_446_744_073_709_551_616.0

PyRandLib/lfib668.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class LFib668( BaseLFib64 ):
109109

110110
#-------------------------------------------------------------------------
111111
# 'protected' constant
112-
_LIST_SIZE = 607 # this 'LFib(2^64, 607, 273, +)' generator is based on a suite containing 607 integers
112+
_STATE_SIZE = 607 # this 'LFib(2^64, 607, 273, +)' generator is based on a suite containing 607 integers
113113

114114

115115
#-------------------------------------------------------------------------
@@ -121,14 +121,14 @@ def random(self) -> float:
121121
# evaluates indexes in suite for the i-273 and i-607 -th values
122122
k273 = self._index-273
123123
if k273 < 0:
124-
k273 += LFib668._LIST_SIZE
124+
k273 += LFib668._STATE_SIZE
125125

126126
# then evaluates current value
127127
myValue = (self._state[k273] + self._state[self._index]) & 0xffff_ffff_ffff_ffff
128128
self._state[self._index] = myValue
129129

130130
# next index
131-
self._index = (self._index+1) % LFib668._LIST_SIZE
131+
self._index = (self._index+1) % LFib668._STATE_SIZE
132132

133133
# then returns float value within [0.0, 1.0)
134134
return myValue * 5.421_010_862_427_522_170_037_3e-20 # / 18_446_744_073_709_551_616.0

PyRandLib/lfib78.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class LFib78( BaseLFib64 ):
108108

109109
#-------------------------------------------------------------------------
110110
# 'protected' constant
111-
_LIST_SIZE = 17 # this 'LFib(2^64, 17, 5, +)' generator is based on a suite containing 17 integers
111+
_STATE_SIZE = 17 # this 'LFib(2^64, 17, 5, +)' generator is based on a suite containing 17 integers
112112

113113

114114
#-------------------------------------------------------------------------
@@ -120,14 +120,14 @@ def random(self) -> float:
120120
# evaluates indexes in suite for the i-5 and i-17 -th values
121121
k5 = self._index-5
122122
if k5 < 0:
123-
k5 += LFib78._LIST_SIZE
123+
k5 += LFib78._STATE_SIZE
124124

125125
# then evaluates current value
126126
myValue = (self._state[k5] + self._state[self._index]) & 0xffff_ffff_ffff_ffff
127127
self._state[self._index] = myValue
128128

129129
# next index
130-
self._index = (self._index+1) % LFib78._LIST_SIZE
130+
self._index = (self._index+1) % LFib78._STATE_SIZE
131131

132132
# then returns float value within [0.0, 1.0)
133133
return myValue * 5.421_010_862_427_522_170_037_3e-20 # / 18_446_744_073_709_551_616.0

PyRandLib/mrgrand1457.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class MRGRand1457( BaseMRG ):
9999

100100
#-------------------------------------------------------------------------
101101
# 'protected' constant
102-
_LIST_SIZE = 47 # this 'DX-47-3' MRG is based on a suite containing 47 integers
103-
_MODULO = 2_147_483_647 # i.e. 0x7fff_ffff, or (1<<31)-1, the modulo for DX-47-3 MRG
102+
_STATE_SIZE = 47 # this 'DX-47-3' MRG is based on a suite containing 47 integers
103+
_MODULO = 2_147_483_647 # i.e. 0x7fff_ffff, or (1<<31)-1, the modulo for DX-47-3 MRG
104104

105105

106106
#-------------------------------------------------------------------------
@@ -112,18 +112,18 @@ def random(self) -> float:
112112
# evaluates indexes in suite for the i-1, i-24 (and i-47) -th values
113113
k1 = self._index-1
114114
if k1 < 0:
115-
k1 = MRGRand1457._LIST_SIZE - 1
115+
k1 = MRGRand1457._STATE_SIZE - 1
116116

117117
k24 = self._index-24
118118
if k24 < 0:
119-
k24 += MRGRand1457._LIST_SIZE
119+
k24 += MRGRand1457._STATE_SIZE
120120

121121
# then evaluates current value
122122
myValue = (67633152 * (self._state[k1] + self._state[k24] + self._state[self._index]) ) % 2_147_483_647
123123
self._state[self._index] = myValue
124124

125125
# next index
126-
self._index = (self._index + 1) % MRGRand1457._LIST_SIZE
126+
self._index = (self._index + 1) % MRGRand1457._STATE_SIZE
127127

128128
# then returns float value within [0.0, 1.0)
129129
return myValue * 4.656_612_873_077_039_257_8e-10 # / 2_147_483_648.0

PyRandLib/mrgrand287.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class MRGRand287( BaseMRG ):
113113

114114
#-------------------------------------------------------------------------
115115
# 'protected' constant
116-
_LIST_SIZE = 256 # this 'Marsa-LFIB4' MRG is based on a suite containing 256 integers
117-
_MODULO = 4_294_967_295 # i.e. 0xffff_ffff, or (1<<32)-1, the modulo for DX-47-3 MRG
116+
_STATE_SIZE = 256 # this 'Marsa-LFIB4' MRG is based on a suite containing 256 integers
117+
_MODULO = 4_294_967_295 # i.e. 0xffff_ffff, or (1<<32)-1, the modulo for DX-47-3 MRG
118118

119119

120120
#-------------------------------------------------------------------------
@@ -129,22 +129,22 @@ def random(self) -> float:
129129
# evaluates indexes in suite for the i-55, i-119, i-179 (and i-256) -th values
130130
k55 = self._index-55
131131
if k55 < 0:
132-
k55 += MRGRand287._LIST_SIZE
132+
k55 += MRGRand287._STATE_SIZE
133133

134134
k119 = self._index-119
135135
if k119 < 0:
136-
k119 += MRGRand287._LIST_SIZE
136+
k119 += MRGRand287._STATE_SIZE
137137

138138
k179 = self._index-179
139139
if k179 < 0:
140-
k179 += MRGRand287._LIST_SIZE
140+
k179 += MRGRand287._STATE_SIZE
141141

142142
# then evaluates current value
143143
myValue = (self._state[k55] + self._state[k119] + self._state[k179] + self._state[self._index]) % 4_294_967_295
144144
self._state[self._index] = myValue
145145

146146
# next index
147-
self._index = (self._index+1) % self._LIST_SIZE
147+
self._index = (self._index+1) % self._STATE_SIZE
148148

149149
# then returns float value within [0.0, 1.0)
150150
return myValue * 2.328_306_436_538_696_289_062_5e-10 # / 4_294_967_296.0

0 commit comments

Comments
 (0)