Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def configure_stream(
bit_gen, kwargs=None, jumped=False, streams=8196, entropy=DEFAULT_ENTOPY
):
bit_generator = bit_gen.__name__
extra_code = extra_initialization = ""
if bit_gen == SFC64 and kwargs["k"] == "weyl":
extra_code = f"""\
base = rg.SFC64(seed_seq)
weyl = base.weyl_increments({streams})
bitgens = [rg.SFC64(seed_seq, k=k) for k in retain]
"""
elif bit_gen == DSFMT:
bit_generator = "Wrapper32"
extra_initialization = DSFMT_WRAPPER
# return configure_dsfmt(streams, entropy=entropy)
kwargs = {} if kwargs is None else kwargs
kwargs_repr = str(kwargs)
return TEMPLATE.render(
bit_generator=bit_generator,
entropy=entropy,
jumped=jumped,
streams=streams,
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):
print("Packing bits")
assert bits > 32
nitems = a.shape[0]
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"]},
Romu: {"variant": ["quad", "trio"]},
PCG64DXSM128,
PCG64DXSM,
LXM,
SFMT,
AESCounter,
ChaCha,
Philox,
ThreeFry,
Xoshiro256,
Xoshiro512,
JSF,
Romu,
RomuTrio,
HC128,
SPECK128,
SFC64,
EFIIX64,
]
if HAS_RDRND:
PRNGS.append(RDRAND)
funcs = OrderedDict()
funcs["Uint32"] = f'integers(2**32, dtype="uint32", size={SIZE})'
funcs["Uint64"] = f'integers(2**64, dtype="uint64", size={SIZE})'
funcs["Uniform"] = f"random(size={SIZE})"
funcs["Expon"] = f"standard_exponential(size={SIZE})"
funcs["Normal"] = f"standard_normal(size={SIZE})"
funcs["Gamma"] = f"standard_gamma(3.0,size={SIZE})"
setup = """