Skip to content

Commit 93b39a2

Browse files
authored
Merge pull request #53 from schmouk/well-impl
Merge branch Well-impl w. branch dev
2 parents 5c18035 + 6a7d818 commit 93b39a2

25 files changed

Lines changed: 1150 additions & 196 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com.
3+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

PyRandLib/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com
3+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

PyRandLib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you decide to use this library, please add the copyright notice to your
99
software as stated in the LICENSE file.
1010

1111
```
12-
Copyright (c) 2016-2022 Philippe Schmouker, <ph.schmouker (at) gmail.com>
12+
Copyright (c) 2016-2025 Philippe Schmouker, <ph.schmouker (at) gmail.com>
1313
1414
Permission is hereby granted, free of charge, to any person obtaining a copy
1515
of this software and associated documentation files (the "Software"), to deal

PyRandLib/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
It is provided under MIT License.
44
Please see files README.md and LICENSE.
55
6-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com
6+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com
77
"""
88

99
from .baselcg import BaseLCG
1010
from .baselfib64 import BaseLFib64
1111
from .basemrg import BaseMRG
1212
from .baserandom import BaseRandom
13+
from .basewell import BaseWELL
1314
from .fastrand32 import FastRand32
1415
from .fastrand63 import FastRand63
1516
from .lfib78 import LFib78
@@ -19,3 +20,7 @@
1920
from .mrgrand287 import MRGRand287
2021
from .mrgrand1457 import MRGRand1457
2122
from .mrgrand49507 import MRGRand49507
23+
from .well512a import Well512a
24+
from .well1024a import Well1024a
25+
from .well19937c import Well19937c
26+
from .well44497b import Well44497b
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
31
"""
4-
Copyright (c) 2021-2022 Philippe Schmouker, schmouk (at) gmail.com
2+
Copyright (c) 2021-2025 Philippe Schmouker, schmouk (at) gmail.com
53
64
Permission is hereby granted, free of charge, to any person obtaining a copy
75
of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +24,10 @@
2624
from typing import List, Tuple, Union
2725

2826
Numerical = Union[ int, float ]
29-
StateType = Union[ Tuple[Numerical], List[Numerical], Tuple[List[Numerical], int] ]
27+
StateType = Union[ Tuple[Numerical], List[Numerical], Tuple[List[Numerical], int], Tuple[Tuple[Numerical], int] ]
3028
SeedStateType = Union[ Numerical, StateType ]
3129

3230

33-
#===== end of PyRandLib.types =====#
31+
#===== end of PyRandLib.annotation_types ===============================
32+
33+
# type: ignore (this comment line is just to avoid boring pylance related error checking)

PyRandLib/baselcg.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
31
"""
4-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com
2+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com
53
64
Permission is hereby granted, free of charge, to any person obtaining a copy
75
of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +30,7 @@ class BaseLCG( BaseRandom ):
3230
3331
This module is part of library PyRandLib.
3432
35-
Copyright (c) 2016-2021 Philippe Schmouker
33+
Copyright (c) 2016-2025 Philippe Schmouker
3634
3735
LCG models evaluate pseudo-random numbers suites x(i) as a simple mathem-
3836
atical function of
@@ -55,9 +53,9 @@ class BaseLCG( BaseRandom ):
5553
5654
Furthermore this class is callable:
5755
rand = BaseLCG()
58-
print( rand() ) # prints a uniform pseudo-random value within [0.0, 1.0)
59-
print( rand(a) ) # prints a uniform pseudo-random value within [0.0, a)
60-
print( rand(a,b) ) # prints a uniform pseudo-random value within [a , b)
56+
print( rand() ) # prints a pseudo-random value within [0.0, 1.0)
57+
print( rand(a) ) # prints a pseudo-random value within [0.0, a)
58+
print( rand(a,b) ) # prints a pseudo-random value within [a , b)
6159
6260
Reminder:
6361
We give you here below a copy of the table of tests for the LCGs that have

PyRandLib/baselfib64.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com
4+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -23,9 +23,9 @@
2323
"""
2424

2525
#=============================================================================
26-
from .baserandom import BaseRandom
27-
from .fastrand32 import FastRand32
28-
from .types import SeedStateType, StateType
26+
from .baserandom import BaseRandom
27+
from .fastrand32 import FastRand32
28+
from .annotation_types import SeedStateType, StateType
2929

3030

3131
#=============================================================================
@@ -36,7 +36,7 @@ class BaseLFib64( BaseRandom ):
3636
on 64-bits generated numbers.
3737
This module is part of library PyRandLib.
3838
39-
Copyright (c) 2016-2021 Philippe Schmouker
39+
Copyright (c) 2016-2025 Philippe Schmouker
4040
4141
Lagged Fibonacci generators LFib( m, r, k, op) use the recurrence
4242
@@ -66,9 +66,9 @@ class BaseLFib64( BaseRandom ):
6666
Example:
6767
6868
rand = BaseLFib()
69-
print( rand() ) # prints a uniform pseudo-random value within [0.0, 1.0)
70-
print( rand(a) ) # prints a uniform pseudo-random value within [0.0, a)
71-
print( rand(a,b) ) # prints a uniform pseudo-random value within [a , b)
69+
print( rand() ) # prints a pseudo-random value within [0.0, 1.0)
70+
print( rand(a) ) # prints a pseudo-random value within [0.0, a)
71+
print( rand(a,b) ) # prints a pseudo-random value within [a , b)
7272
7373
Inheriting classes have to define class attribute '_LIST_SIZE'. See LFib78 for an
7474
example.
@@ -109,7 +109,7 @@ def __init__(self, _seedState: SeedStateType = None) -> None:
109109
"""
110110
super().__init__( _seedState )
111111
# this call creates the two attributes
112-
# self._list and self._index, and sets them
112+
# self._state and self._index, and sets them
113113
# since it internally calls self.setstate().
114114

115115

@@ -132,7 +132,7 @@ def getstate(self) -> StateType:
132132
tuple containing a list of self._LIST_SIZE integers and an
133133
index in this list (index value being then in range(0,self._LIST_SIZE).
134134
"""
135-
return (self._list[:], self._index)
135+
return (self._state[:], self._index)
136136

137137

138138
#------------------------------------------------------------------------=
@@ -156,19 +156,19 @@ def setstate(self, _seedState: StateType) -> None:
156156

157157
if count == 0:
158158
self._initIndex( 0 )
159-
self._initList()
159+
self._initState()
160160

161161
elif count == 1:
162162
self._initIndex( 0 )
163-
self._initList( _seedState[0] )
163+
self._initState( _seedState[0] )
164164

165165
else:
166166
self._initIndex( _seedState[1] )
167-
self._list = _seedState[0][:]
167+
self._state = _seedState[0][:]
168168

169169
except:
170170
self._initIndex( 0 )
171-
self._initList( _seedState )
171+
self._initState( _seedState )
172172

173173

174174
#------------------------------------------------------------------------=
@@ -182,7 +182,7 @@ def _initIndex(self, _index: int) -> None:
182182

183183

184184
#------------------------------------------------------------------------=
185-
def _initList(self, _initialSeed: StateType = None) -> None:
185+
def _initState(self, _initialSeed: StateType = None) -> None:
186186
"""Inits the internal list of values.
187187
188188
Inits the internal list of values according to some initial
@@ -191,7 +191,7 @@ def _initList(self, _initialSeed: StateType = None) -> None:
191191
current local time value is used as initial seed value.
192192
"""
193193
myRand = FastRand32( _initialSeed )
194-
self._list = [ (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._LIST_SIZE) ]
195195

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

PyRandLib/basemrg.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
31
"""
4-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com
2+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com
53
64
Permission is hereby granted, free of charge, to any person obtaining a copy
75
of this software and associated documentation files (the "Software"), to deal
@@ -23,9 +21,9 @@
2321
"""
2422

2523
#=============================================================================
26-
from .baserandom import BaseRandom
27-
from .fastrand32 import FastRand32
28-
from .types import SeedStateType, StateType
24+
from .baserandom import BaseRandom
25+
from .fastrand32 import FastRand32
26+
from .annotation_types import SeedStateType, StateType
2927

3028

3129
#=============================================================================
@@ -34,7 +32,7 @@ class BaseMRG( BaseRandom ):
3432
3533
This module is part of library PyRandLib.
3634
37-
Copyright (c) 2016-2021 Philippe Schmouker
35+
Copyright (c) 2016-2025 Philippe Schmouker
3836
3937
Multiple Recursive Generators (MRGs) uses recurrence to evaluate pseudo-random
4038
numbers suites. Recurrence is of the form:
@@ -63,15 +61,15 @@ class BaseMRG( BaseRandom ):
6361
Example:
6462
6563
rand = BaseMRG()
66-
print( rand() ) # prints a uniform pseudo-random value within [0.0, 1.0)
67-
print( rand(a) ) # prints a uniform pseudo-random value within [0.0, a)
68-
print( rand(a,b) ) # prints a uniform pseudo-random value within [a , b)
64+
print( rand() ) # prints a pseudo-random value within [0.0, 1.0)
65+
print( rand(a) ) # prints a pseudo-random value within [0.0, a)
66+
print( rand(a,b) ) # prints a pseudo-random value within [a , b)
6967
7068
Inheriting classes have to define class attributes '_LIST_SIZE' and '_MODULO'. See
7169
MRGRand287 for an example.
7270
7371
Reminder:
74-
We give you here below a copy of the table of tests for the LCGs that have
72+
We give you here below a copy of the table of tests for the MRGs that have
7573
been implemented in PyRandLib, as provided in paper "TestU01, ..." - see
7674
file README.md.
7775
@@ -105,7 +103,7 @@ def __init__(self, _seedState: SeedStateType = None) -> None:
105103
"""
106104
super().__init__( _seedState )
107105
# this call creates the two attributes
108-
# self._list and self._index, and sets them
106+
# self._state and self._index, and sets them
109107
# since it internally calls self.setstate().
110108

111109

@@ -128,7 +126,7 @@ def getstate(self) -> StateType:
128126
tuple containing a list of self._LIST_SIZE integers and an
129127
index in this list (index value being then in range(0,self._LIST_SIZE).
130128
"""
131-
return (self._list[:], self._index)
129+
return (self._state[:], self._index)
132130

133131

134132
#------------------------------------------------------------------------=
@@ -152,19 +150,19 @@ def setstate(self, _seedState: StateType) -> None:
152150

153151
if count == 0:
154152
self._initIndex( 0 )
155-
self._initList()
153+
self._initState()
156154

157155
elif count == 1:
158156
self._initIndex( 0 )
159-
self._initList( _seedState[0] )
157+
self._initState( _seedState[0] )
160158

161159
else:
162160
self._initIndex( _seedState[1] )
163-
self._list = _seedState[0][:]
161+
self._state = _seedState[0][:]
164162

165163
except:
166164
self._initIndex( 0 )
167-
self._initList( _seedState )
165+
self._initState( _seedState )
168166

169167

170168
#------------------------------------------------------------------------=
@@ -178,7 +176,7 @@ def _initIndex(self, _index: int) -> None:
178176

179177

180178
#------------------------------------------------------------------------=
181-
def _initList(self, _initialSeed: StateType = None) -> None:
179+
def _initState(self, _initialSeed: StateType = None) -> None:
182180
"""Inits the internal list of values.
183181
184182
Inits the internal list of values according to some initial
@@ -188,7 +186,7 @@ def _initList(self, _initialSeed: StateType = None) -> None:
188186
"""
189187
# feeds the list according to an initial seed and the value+1 of the modulo.
190188
myRand = FastRand32( _initialSeed )
191-
self._list = [ int(myRand(self._MODULO+1)) for _ in range(self._LIST_SIZE) ]
189+
self._state = [ int(myRand(self._MODULO+1)) for _ in range(self._LIST_SIZE) ]
192190

193191

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

PyRandLib/baserandom.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
31
"""
4-
Copyright (c) 2016-2022 Philippe Schmouker, schmouk (at) gmail.com
2+
Copyright (c) 2016-2025 Philippe Schmouker, schmouk (at) gmail.com
53
64
Permission is hereby granted, free of charge, to any person obtaining a copy
75
of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +24,7 @@
2624
from random import Random
2725
from typing import Any, List, Tuple, Union
2826

29-
from .types import Numerical, SeedStateType, StateType
27+
from .annotation_types import Numerical, SeedStateType, StateType
3028

3129

3230
#=============================================================================
@@ -35,7 +33,7 @@ class BaseRandom( Random ):
3533
3634
This module is part of library PyRandLib.
3735
38-
Copyright (c) 2016-2021 Philippe Schmouker
36+
Copyright (c) 2016-2025 Philippe Schmouker
3937
4038
See FastRand32 for a 2^32 (i.e. 4.3e+9) period LC-Generator and FastRand63 for a
4139
2^63 (i.e. about 9.2e+18) period LC-Generator with low computation time.
@@ -264,13 +262,13 @@ def __call__(self, _max : Union[Numerical,
264262
times = 1
265263

266264
if isinstance( _max, int ):
267-
ret = [ self.randint(0, _max) for _ in range(times) ]
265+
ret = [ int(_max * self.random()) for _ in range(times) ]
268266
elif isinstance( _max, float ):
269-
ret = [ self.uniform( 0.0, _max ) for _ in range(times) ]
267+
ret = [ _max * self.random() for _ in range(times) ]
270268
else:
271269
try:
272270
if times == 1:
273-
ret = [ self(m,1) for m in _max]
271+
ret = [ self(m,1) for m in _max ]
274272
else:
275273
ret = [ [self(m,1) for m in _max] for _ in range(times) ]
276274
except:

0 commit comments

Comments
 (0)