Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PyRandLib/basepcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#=============================================================================
class BasePCG( BaseRandom ):
"""Definition of the base class for all PCG pseudo-random generators.
"""Definition of the base class for all Permuted Congruential Generator pseudo-random generators.

This module is part of library PyRandLib.

Expand Down
1 change: 1 addition & 0 deletions PyRandLib/basesquares.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .annotation_types import SeedStateType, StatesList
from .splitmix import SplitMix32


#=============================================================================
class BaseSquares( BaseRandom ):
"""Definition of the base class for the Squares counter-based pseudo-random Generator.
Expand Down
14 changes: 6 additions & 8 deletions PyRandLib/basewell.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#=============================================================================
from .baserandom import BaseRandom
from .annotation_types import Numerical, SeedStateType, StateType
from .annotation_types import SeedStateType, StateType
from .splitmix import SplitMix32


Expand Down Expand Up @@ -232,7 +232,7 @@ def _M3_neg(cls, x: int, t: int) -> int:
@classmethod
def _M4(cls, x: int, a: int) -> int:
#assert 0 <= a <= 0xffff_ffff
return x >> 1 ^ a if x & 0x8000_0000 else x >> 1
return (x >> 1) ^ a if x & 0x8000_0000 else x >> 1

#-------------------------------------------------------------------------
@classmethod
Expand Down Expand Up @@ -270,12 +270,10 @@ def _tempering(cls, x: int, b: int, c: int) -> int:
#assert 0 <= b <= 0xffff_ffff
#assert 0 <= c <= 0xffff_ffff
#assert 0 <= w <= 32
# z = ((z << (32 - w)) & 0xffff_ffff) >> (32 - w)
# notice: the generic algorithm truncs x on w-bits. All of the implemented
# ones in PyRandLib are set on 32-bits. So, no truncation takes place here
z = x
z = z ^ (((z << 7) & 0xffff_ffff) & b)
return z ^ (((z << 15) & 0xffff_ffff) & c)
# notice: the generic algorithm truncs x on w-bits. All of the implemented
# ones in PyRandLib are set on 32-bits. So, no truncation takes place here
x = x ^ (((x << 7) & 0xffff_ffff) & b)
return x ^ (((x << 15) & 0xffff_ffff) & c)

#-------------------------------------------------------------------------
@property
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/basexoroshiro.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BaseXoroshiro( BaseRandom ):
"""


_MODULO = (1 << 64) - 1
_MODULO: int = (1 << 64) - 1


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/lfib116.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LFib116( BaseLFib64 ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 55 # this 'LFib(2^64, 55, 24, +)' generator is based on a suite containing 55 integers
_STATE_SIZE: int = 55 # this 'LFib(2^64, 55, 24, +)' generator is based on a suite containing 55 integers


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/lfib1340.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class LFib1340( BaseLFib64 ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 1279 # this 'LFib(2^64, 1279, 861, +)' generator is based on a suite containing 1279 integers
_STATE_SIZE: int = 1279 # this 'LFib(2^64, 1279, 861, +)' generator is based on a suite containing 1279 integers


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/lfib668.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LFib668( BaseLFib64 ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 607 # this 'LFib(2^64, 607, 273, +)' generator is based on a suite containing 607 integers
_STATE_SIZE: int = 607 # this 'LFib(2^64, 607, 273, +)' generator is based on a suite containing 607 integers


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/lfib78.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LFib78( BaseLFib64 ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 17 # this 'LFib(2^64, 17, 5, +)' generator is based on a suite containing 17 integers
_STATE_SIZE: int = 17 # this 'LFib(2^64, 17, 5, +)' generator is based on a suite containing 17 integers


#-------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions PyRandLib/melg19937.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

#=============================================================================
from .basemelg import BaseMELG
from .basemelg import BaseMELG


#=============================================================================
Expand Down Expand Up @@ -94,7 +94,7 @@ class Melg19937( BaseMELG ):

#-------------------------------------------------------------------------
# 'protected' constants
_STATE_SIZE = 312
_STATE_SIZE: int = 312
_A_COND = (0, 0x5c32_e06d_f730_fc42) # this tuple will avoid an 'if' in method 'next()'


Expand Down
4 changes: 2 additions & 2 deletions PyRandLib/melg44497.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

#=============================================================================
from .basemelg import BaseMELG
from .basemelg import BaseMELG


#=============================================================================
Expand Down Expand Up @@ -93,7 +93,7 @@ class Melg44497( BaseMELG ):

#-------------------------------------------------------------------------
# 'protected' constants
_STATE_SIZE = 696
_STATE_SIZE: int = 696
_A_COND = (0, 0x4fa9_ca36_f293_c9a9)


Expand Down
4 changes: 2 additions & 2 deletions PyRandLib/melg607.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

#=============================================================================
from .basemelg import BaseMELG
from .basemelg import BaseMELG


#=============================================================================
Expand Down Expand Up @@ -93,7 +93,7 @@ class Melg607( BaseMELG ):

#-------------------------------------------------------------------------
# 'protected' constants
_STATE_SIZE = 10 # the internal state of this PRNG is set on ten 64-bits integers N=10
_STATE_SIZE: int = 10 # the internal state of this PRNG is set on ten 64-bits integers N=10
_A_COND = (0, 0x81f1_fd68_0123_48bc) # this tuple will avoid an 'if' in method 'next()', a=0x81f1...


Expand Down
4 changes: 2 additions & 2 deletions PyRandLib/mrg1457.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class Mrg1457( BaseMRG ):

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


#-------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions PyRandLib/mrg287.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class Mrg287( BaseMRG ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 256 # this 'Marsa-LFIB4' MRG is based on a suite containing 256 integers
_MODULO = 0xffff_ffff
_STATE_SIZE: int = 256 # this 'Marsa-LFIB4' MRG is based on a suite containing 256 integers
_MODULO : int = 0xffff_ffff


#-------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions PyRandLib/mrg49507.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class Mrg49507( BaseMRG ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 1597 # this 'DX-1597-2-7' MRG is based on a suite containing 1597 integers
_MODULO = 2_147_483_647 # i.e. 0x7fffffff, or (1<<31)-1, the modulo for DX-1597-2-7 MRG
_STATE_SIZE: int = 1597 # this 'DX-1597-2-7' MRG is based on a suite containing 1597 integers
_MODULO : int = 2_147_483_647 # i.e. 0x7fffffff, or (1<<31)-1, the modulo for DX-1597-2-7 MRG


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/pcg1024_32.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Pcg1024_32( Pcg64_32 ):
"""

#-------------------------------------------------------------------------
_EXTENDED_STATE_SIZE = 1024
_EXTENDED_STATE_SIZE: int = 1024


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/well1024a.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Well1024a( BaseWELL ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 32 # this Well1024a PRNG internal state is based on a suite containing 32 integers (32-bits wide each)
_STATE_SIZE: int = 32 # this Well1024a PRNG internal state is based on a suite containing 32 integers (32-bits wide each)


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/well19937c.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Well19937c( BaseWELL ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 624 # this Well19937c PRNG internal state is based on a suite containing 624 integers (32-bits wide each)
_STATE_SIZE: int = 624 # this Well19937c PRNG internal state is based on a suite containing 624 integers (32-bits wide each)


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/well44497b.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Well44497b( BaseWELL ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 1391 # this Well44497b PRNG internal state is based on a suite containing 1391 integers (32-bits wide each)
_STATE_SIZE: int = 1391 # this Well44497b PRNG internal state is based on a suite containing 1391 integers (32-bits wide each)


#-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion PyRandLib/well512a.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Well512a( BaseWELL ):

#-------------------------------------------------------------------------
# 'protected' constant
_STATE_SIZE = 16 # this Well512a PRNG internal state is based on a suite containing 16 integers (32-bits wide each)
_STATE_SIZE: int = 16 # this Well512a PRNG internal state is based on a suite containing 16 integers (32-bits wide each)


#-------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions PyRandLib/xoroshiro1024.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class Xoroshiro1024( BaseXoroshiro ):
should definitively pass.
"""
#-------------------------------------------------------------------------
_STATE_SIZE = 16
_SIZE_MODULO = 0xf
_STATE_SIZE : int = 16
_SIZE_MODULO: int = 0xf # optimization here, to use operand &


#-------------------------------------------------------------------------
def __init__(self, _seedState: Union[Numerical, SeedStateType] = None) -> None:
Expand Down
3 changes: 3 additions & 0 deletions Python3.6/PyRandLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
from .xoroshiro256 import Xoroshiro256
from .xoroshiro512 import Xoroshiro512
from .xoroshiro1024 import Xoroshiro1024


#===== end of package module __init__.py ===============================
3 changes: 2 additions & 1 deletion Python3.6/PyRandLib/basepcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#=============================================================================
class BasePCG( BaseRandom ):
"""Definition of the base class for all PCG pseudo-random generators.
"""Definition of the base class for all Permuted Congruential Generator pseudo-random generators.

This module is part of library PyRandLib.

Expand Down Expand Up @@ -114,4 +114,5 @@ def getstate(self) -> int:
"""
return self._state


#===== end of module basepcg.py ========================================
1 change: 1 addition & 0 deletions Python3.6/PyRandLib/basesquares.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .annotation_types import SeedStateType, StatesList
from .splitmix import SplitMix32


#=============================================================================
class BaseSquares( BaseRandom ):
"""Definition of the base class for the Squares counter-based pseudo-random Generator.
Expand Down
53 changes: 16 additions & 37 deletions Python3.6/PyRandLib/basewell.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#=============================================================================
from .baserandom import BaseRandom
from .annotation_types import Numerical, SeedStateType, StateType
from .annotation_types import SeedStateType, StateType
from .splitmix import SplitMix32


Expand Down Expand Up @@ -232,7 +232,7 @@ def _M3_neg(cls, x: int, t: int) -> int:
@classmethod
def _M4(cls, x: int, a: int) -> int:
#assert 0 <= a <= 0xffff_ffff
return x >> 1 ^ a if x & 0x8000_0000 else x >> 1
return (x >> 1) ^ a if x & 0x8000_0000 else x >> 1

#-------------------------------------------------------------------------
@classmethod
Expand All @@ -256,7 +256,7 @@ def _M6(cls, x: int, q: int, t: int, s: int, a: int) -> int:
#assert 0 <= s < 32
#assert 0 <= a <= 0xffff_ffff
y = (((x << q) & 0xffff_ffff) ^ (x >> (32 - q))) & cls._d(s)
return y ^ a if x & (1 << t) else y
return (y ^ a) if (x & (1<<t)) else y

#-------------------------------------------------------------------------
@classmethod
Expand All @@ -269,41 +269,20 @@ def _d(cls, s: int) -> int:
def _tempering(cls, x: int, b: int, c: int) -> int:
#assert 0 <= b <= 0xffff_ffff
#assert 0 <= c <= 0xffff_ffff
#assert 0 <= w <= 32
# z = ((z << (32 - w)) & 0xffff_ffff) >> (32 - w)
# notice: the generic algorithm truncs x on w-bits. All of the implemented
# ones in PyRandLib are set on 32-bits. So, no truncation takes place here
z = x
z = z ^ (((z << 7) & 0xffff_ffff) & b)
return z ^ (((z << 15) & 0xffff_ffff) & c)
# notice: the generic algorithm truncs x on w-bits. All of the implemented
# ones in PyRandLib are set on 32-bits. So, no truncation takes place here
x = x ^ (((x << 7) & 0xffff_ffff) & b)
return x ^ (((x << 15) & 0xffff_ffff) & c)

#-------------------------------------------------------------------------
@property
def _a1(self):
return 0xda44_2d24

@property
def _a2(self):
return 0xd3e4_3ffd

@property
def _a3(self):
return 0x8bdc_b91e

@property
def _a4(self):
return 0x86a9_d87e

@property
def _a5(self):
return 0xa8c2_96d1

@property
def _a6(self):
return 0x5d6b_45cc

@property
def _a7(self):
return 0xb729_fcec
# definition of algorithm constants
_a1: int = 0xda44_2d24
_a2: int = 0xd3e4_3ffd
_a3: int = 0x8bdc_b91e
_a4: int = 0x86a9_d87e
_a5: int = 0xa8c2_96d1
_a6: int = 0x5d6b_45cc
_a7: int = 0xb729_fcec


#===== end of module basewell.py =======================================
4 changes: 1 addition & 3 deletions Python3.6/PyRandLib/basexoroshiro.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class BaseXoroshiro( BaseRandom ):
should definitively pass.
"""


#-------------------------------------------------------------------------
_NORMALIZE: float = 5.421_010_862_427_522_170_037_3e-20 # i.e. 1.0 / (1 << 64)
"""The value of this class attribute MUST BE OVERRIDDEN in inheriting
Expand All @@ -106,8 +105,7 @@ class BaseXoroshiro( BaseRandom ):
than 32 bits.
"""


_MODULO = (1 << 64) - 1
_MODULO: int = (1 << 64) - 1


#-------------------------------------------------------------------------
Expand Down
Loading