Skip to content

Commit 83f3c5c

Browse files
committed
#14 - Release 1.1.0
Finally modified copyright dates (2021); added Unix and Utf-8 goodies at top of modules; conforms now to new documentation rules; uses now library `typing` for types annotations in methods signatures.
1 parent 4564111 commit 83f3c5c

19 files changed

+216
-175
lines changed

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-2020 Philippe Schmouker, schmouk (at) typee.ovh.
3+
Copyright (c) 2016-2021 Philippe Schmouker, schmouk (at) typee.ovh.
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-2020 Philippe Schmouker, schmouk (at) typee.ovh
3+
Copyright (c) 2016-2021 Philippe Schmouker, schmouk (at) typee.ovh
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: 4 additions & 3 deletions
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-2020 Philippe Schmouker, schmouk (at) typee.ovh
12+
Copyright (c) 2016-2021 Philippe Schmouker, schmouk (at) typee.ovh
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
@@ -106,7 +106,8 @@ implemented in PyRabdLib, as provided in [1].
106106

107107

108108
## Implementation
109-
Current implementation of PyRandLib uses Python 3.x with no Cython version.
109+
Current implementation of PyRandLib uses Python 3.x with no Cython version.
110+
It has been tested with Python 3.8 but should run with most of Python 3 suvbversions.
110111

111112
Python 2.7 could be later available, if asked for. Cython implementations
112113
could also be later available.
@@ -337,7 +338,7 @@ Please notice that the TestUO1 article states that the operator should be
337338

338339

339340

340-
### LFibRand1340
341+
### LFibRand1340 - 2^1340 periodicity
341342

342343
**LFibRand1340** implements an LFib 64-bits generator proposed by George
343344
Marsaglia in [4]. This PRG uses the recurrence

PyRandLib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
It is provided under MIT License.
44
Please see files README.md and LICENSE.
55
6-
Copyright (c) 2016-2020 Philippe Schmouker
6+
Copyright (c) 2016-2021 Philippe Schmouker
77
"""
88

99
from .baselcg import BaseLCG

PyRandLib/baselcg.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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
76
Permission is hereby granted, free of charge, to any person obtaining a copy
87
of this software and associated documentation files (the "Software"), to deal
@@ -29,11 +28,11 @@
2928

3029
#=============================================================================
3130
class BaseLCG( BaseRandom ):
32-
"""
33-
Definition of the base class for all LCG pseudo-random generators.
31+
"""Definition of the base class for all LCG pseudo-random generators.
32+
3433
This module is part of library PyRandLib.
3534
36-
Copyright (c) 2016-2020 Philippe Schmouker
35+
Copyright (c) 2016-2021 Philippe Schmouker
3736
3837
LCG models evaluate pseudo-random numbers suites x(i) as a simple mathem-
3938
atical function of
@@ -78,30 +77,31 @@ class BaseLCG( BaseRandom ):
7877
should definitively pass.
7978
"""
8079

81-
#=========================================================================
80+
#------------------------------------------------------------------------=
8281
def __init__(self, _seedState: int = None) -> None:
83-
"""
84-
Constructor. Should inSeed be None or not an integer then
85-
the local time is used (with its shuffled value) as a seed.
82+
"""Constructor.
83+
84+
Should inSeed be None or not an integer then the local
85+
time is used (with its shuffled value) as a seed.
8686
"""
8787
super().__init__( _seedState ) # this call creates attribute self._value and sets it
8888

8989

90-
#=========================================================================
90+
#------------------------------------------------------------------------=
9191
def random(self) -> float:
92-
"""
93-
This is the core of the pseudo-random generator.
92+
"""This is the core of the pseudo-random generator.
93+
9494
Returned values are within [0.0, 1.0).
9595
Inheriting classes HAVE TO IMPLEMENT this method - see FastRand32
9696
for an example. It should use and initialize attribute self._value.
9797
"""
98-
raise NotImplementedError
98+
raise NotImplementedError()
9999

100100

101-
#=========================================================================
101+
#------------------------------------------------------------------------=
102102
def getstate(self) -> int:
103-
"""
104-
Returns an object capturing the current internal state of the generator.
103+
"""Returns an object capturing the current internal state of the generator.
104+
105105
This object can be passed to setstate() to restore the state.
106106
For LCG, the state is defined with a single integer, 'self._value',
107107
which has to be used in methods 'random() and 'setstate() of every
@@ -110,16 +110,17 @@ def getstate(self) -> int:
110110
return self._value
111111

112112

113-
#=========================================================================
113+
#------------------------------------------------------------------------=
114114
def setstate(self, _state: int) -> None:
115-
"""
115+
"""Restores the internal state of the generator.
116+
116117
_state should have been obtained from a previous call to getstate(),
117118
and setstate() restores the internal state of the generator to what
118119
it was at the time setstate() was called.
119120
Inheriting classes HAVE TO IMPLEMENT this method - see FastRand32
120121
for an example. It should initialize attribute self._value.
121122
"""
122-
raise NotImplementedError
123+
raise NotImplementedError()
123124

124125

125126
#===== end of module baselcg.py ========================================

PyRandLib/baselfib64.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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
76
Permission is hereby granted, free of charge, to any person obtaining a copy
87
of this software and associated documentation files (the "Software"), to deal
@@ -26,16 +25,18 @@
2625
#=============================================================================
2726
from .baserandom import BaseRandom
2827
from .fastrand63 import FastRand63
28+
from .types import SeedStateType, StateType
2929

3030

3131
#=============================================================================
3232
class BaseLFib64( BaseRandom ):
33-
"""
33+
"""The base class for all LFib PRG based on 64-bits numbers.
34+
3435
Definition of the base class for all LFib pseudo-random generators based
3536
on 64-bits generated numbers.
3637
This module is part of library PyRandLib.
3738
38-
Copyright (c) 2016-2020 Philippe Schmouker
39+
Copyright (c) 2016-2021 Philippe Schmouker
3940
4041
Lagged Fibonacci generators LFib( m, r, k, op) use the recurrence
4142
@@ -92,10 +93,10 @@ class BaseLFib64( BaseRandom ):
9293
should definitively pass.
9394
"""
9495

95-
#=========================================================================
96-
def __init__(self, _seedState: tuple = None) -> None:
97-
"""
98-
Constructor.
96+
#------------------------------------------------------------------------=
97+
def __init__(self, _seedState: SeedStateType = None) -> None:
98+
"""Constructor.
99+
99100
_seedState is either a valid state, an integer, a float or None.
100101
About valid state: this is a tuple containing a list of
101102
self._LIST_SIZE integers and an index in this list (index value
@@ -112,31 +113,32 @@ def __init__(self, _seedState: tuple = None) -> None:
112113
# since it internally calls self.setstate().
113114

114115

115-
#=========================================================================
116+
#------------------------------------------------------------------------=
116117
def random(self) -> float:
117-
"""
118-
This is the core of the pseudo-random generator.
118+
"""This is the core of the pseudo-random generator.
119+
119120
Returned values are within [0.0, 1.0).
120121
Inheriting classes HAVE TO IMPLEMENT this method - see LFib78
121122
for an example.
122123
"""
123-
raise NotImplementedError
124+
raise NotImplementedError()
124125

125126

126-
#=========================================================================
127-
def getstate(self) -> tuple:
128-
"""
129-
Return an object capturing the current internal state of the generator.
127+
#------------------------------------------------------------------------=
128+
def getstate(self) -> StateType:
129+
"""Returns an object capturing the current internal state of the generator.
130+
130131
This object can be passed to setstate() to restore the state. It is a
131132
tuple containing a list of self._LIST_SIZE integers and an
132133
index in this list (index value being then in range(0,self._LIST_SIZE).
133134
"""
134135
return (self._list[:], self._index)
135136

136137

137-
#=========================================================================
138-
def setstate(self, _seedState: tuple) -> None:
139-
"""
138+
#------------------------------------------------------------------------=
139+
def setstate(self, _seedState: StateType) -> None:
140+
"""Restores the internal state of the generator.
141+
140142
_seedState should have been obtained from a previous call to
141143
getstate(), and setstate() restores the internal state of the
142144
generator to what it was at the time setstate() was called.
@@ -162,20 +164,20 @@ def setstate(self, _seedState: tuple) -> None:
162164
self._list = _seedState[0][:]
163165

164166

165-
#=========================================================================
167+
#------------------------------------------------------------------------=
166168
def _initIndex(self, _index: int) -> None:
167-
"""
168-
Inits the internal index pointing to the internal list.
169+
"""Inits the internal index pointing to the internal list.
169170
"""
170171
try:
171172
self._index = int( _index ) % self._LIST_SIZE
172173
except:
173174
self._index = 0
174175

175176

176-
#=========================================================================
177-
def _initList(self, _initialSeed: list = None) -> None:
178-
"""
177+
#------------------------------------------------------------------------=
178+
def _initList(self, _initialSeed: StateType = None) -> None:
179+
"""Inits the internal list of values.
180+
179181
Inits the internal list of values according to some initial
180182
seed that has to be an integer or a float ranging within
181183
[0.0, 1.0). Should it be None or anything else then the

PyRandLib/basemrg.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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
76
Permission is hereby granted, free of charge, to any person obtaining a copy
87
of this software and associated documentation files (the "Software"), to deal
@@ -26,15 +25,16 @@
2625
#=============================================================================
2726
from .baserandom import BaseRandom
2827
from .fastrand32 import FastRand32
28+
from .types import SeedStateType, StateType
2929

3030

3131
#=============================================================================
3232
class 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

Comments
 (0)