Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Xoshiro256,
Xoshiro512,
)
ALL_BIT_GENS = [
AESCounter,
ChaCha,
DSFMT,
EFIIX64,
HC128,
JSF,
LXM,
PCG64,
LCG128Mix,
MT19937,
Philox,
SFC64,
SFMT,
SPECK128,
ThreeFry,
Xoshiro256,
Xoshiro512,
Romu,
]
JUMPABLE = [bg for bg in ALL_BIT_GENS if hasattr(bg, "jumped")]
SPECIALS = {
ChaCha: {"rounds": [8, 20]},
JSF: {"seed_size": [1, 3]},
SFC64: {"k": [1, 3394385948627484371, "weyl"]},
LCG128Mix: {"output": ["upper"]},
PCG64: {"variant": ["dxsm", "dxsm-128", "xsl-rr"]},
def __init__(self, *args, **kwargs):
if "size" in kwargs:
del kwargs["size"]
super().__init__(*args, size=32, **kwargs)
class Philox4x32(Philox):
canonical_repr = "Philox(n=4, w=32)"
def __init__(self, *args, **kwargs):
if "width" in kwargs:
del kwargs["width"]
super().__init__(*args, width=32, **kwargs)
class Philox2x64(Philox):
canonical_repr = "Philox(n=2, w=64)"
def __init__(self, *args, **kwargs):
if "number" in kwargs:
del kwargs["number"]
super().__init__(*args, number=2, **kwargs)
class RomuTrio(Romu):
canonical_repr = 'Romu(variant="trio")'
def __init__(self, *args, **kwargs):
if "variant" in kwargs:
del kwargs["variant"]
super().__init__(*args, variant="trio")
import numpy as np
import randomgen as rg
BUFFER_SIZE = 256 * 2 ** 20
DESCRIPTION = """
A driver that simplifies testing bit generators using PractRand.
"""
CONFIG = {
rg.PCG32: {"output": 32, "seed": 64, "seed_size": 64},
rg.PCG64: {"output": 64, "seed": 128, "seed_size": 128},
rg.ThreeFry: {"output": 64, "seed": 256, "seed_size": 64},
rg.Xoshiro256: {"output": 64, "seed": 256, "seed_size": 64},
rg.Philox: {"output": 64, "seed": 256, "seed_size": 64},
rg.SFMT: {"output": 64, "seed": 128, "seed_size": 32},
rg.LXM: {"output": 64, "seed": 128, "seed_size": 32},
rg.SFC64: {"output": 64, "seed": 128, "seed_size": 32},
rg.AESCounter: {"output": 64, "seed": 128, "seed_size": 32},
}
def reorder_bytes(a):
dtype = a.dtype
assert dtype in (np.uint32, np.uint64)
cols = 8 if dtype == np.uint64 else 4
a = a.view(np.uint8).reshape((-1, cols))
return a.ravel("F").view(dtype)
def pack_bits(a, bits):
JSF32,
Philox4x32,
ThreeFry2x64,
ThreeFry4x32,
Philox2x64,
DSFMT,
MT64,
MT19937,
PCG64,
PCG64DXSM128,
PCG64DXSM,
LXM,
SFMT,
AESCounter,
ChaCha,
Philox,
ThreeFry,
Xoshiro256,
Xoshiro512,
JSF,
Romu,
RomuTrio,
HC128,
SPECK128,
SFC64,
EFIIX64,
]
if HAS_RDRND:
PRNGS.append(RDRAND)
canonical_repr = "ChaCha(rounds=8)"
def __init__(self, *args, **kwargs):
if "rounds" in kwargs:
del kwargs["rounds"]
super().__init__(*args, rounds=8, **kwargs)
class JSF32(JSF):
def __init__(self, *args, **kwargs):
if "size" in kwargs:
del kwargs["size"]
super().__init__(*args, size=32, **kwargs)
class Philox4x32(Philox):
canonical_repr = "Philox(n=4, w=32)"
def __init__(self, *args, **kwargs):
if "width" in kwargs:
del kwargs["width"]
super().__init__(*args, width=32, **kwargs)
class Philox2x64(Philox):
canonical_repr = "Philox(n=2, w=64)"
def __init__(self, *args, **kwargs):
if "number" in kwargs:
del kwargs["number"]
super().__init__(*args, number=2, **kwargs)