How to use the randomgen.RandomGenerator function in randomgen

To help you get started, we’ve selected a few randomgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bethgelab / foolbox / foolbox / attacks / boundary_attack.py View on Github external
def sample_std_normal(thread_id, shape, dtype):
                # create a thread-specifc RNG
                rng = randomgen.RandomGenerator(
                    randomgen.Xoroshiro128(seed=20 + thread_id)
                )

                t = threading.currentThread()
                while getattr(t, "do_run", True):
                    rnd_normal = rng.standard_normal(size=shape, dtype=dtype)
                    rnd_normal_queue.put(rnd_normal)
github MartinThoma / algorithms / Python / random / generate_number_image.py View on Github external
"ThreeFry",
    ]
    if prng not in allowed_prngs:
        raise ValueError(f"prng={prng} is not in {allowed_prngs}")
    arr = np.zeros((size, size))
    for i in range(size):
        if prng == "python":
            random.seed(i)
        elif prng == "numpy":
            np.random.seed(i)
        elif prng == "java":
            rnd = javarandom.Random(i)
        elif prng == "Xoroshiro128":
            rnd = RandomGenerator(Xoroshiro128())
        elif prng == "Xorshift1024":
            rnd = RandomGenerator(Xorshift1024())
        elif prng == "ThreeFry":
            rnd = RandomGenerator(ThreeFry())
        elif prng == "MT19937":
            rnd = Generator(MT19937())
        elif prng == "Philox":
            rnd = Generator(Philox())
        elif prng == "SFC64":
            rnd = Generator(SFC64())

        for j in range(size):
            if prng == "python":
                random_number = random.random()
            elif prng == "numpy":
                random_number = np.random.random()
            elif prng == "java":
                random_number = rnd.nextDouble()
github bethgelab / foolbox / foolbox / attacks / boundary_attack.py View on Github external
spherical_step,
        source_step,
        internal_dtype,
        rng=None,
    ):

        if rng is None:
            try:
                import randomgen
            except ImportError:  # pragma: no cover
                raise ImportError(
                    "To use the BoundaryAttack,"
                    " please install the randomgen"
                    " module (e.g. pip install randomgen)"
                )
            rng = randomgen.RandomGenerator()

        # ===========================================================
        # perform initial work
        # ===========================================================

        assert original.dtype == internal_dtype
        assert perturbed.dtype == internal_dtype

        shape = original.shape

        min_, max_ = bounds

        # ===========================================================
        # draw a random direction
        # ===========================================================
github bethgelab / foolbox / foolbox / attacks / boundary_attack.py View on Github external
spherical_step,
        source_step,
        internal_dtype,
        rng=None,
    ):

        if rng is None:
            try:
                import randomgen
            except ImportError:  # pragma: no cover
                raise ImportError(
                    "To use the BoundaryAttack,"
                    " please install the randomgen"
                    " module (e.g. pip install randomgen)"
                )
            rng = randomgen.RandomGenerator()

        # ===========================================================
        # perform initial work
        # ===========================================================

        assert original.dtype == internal_dtype
        assert perturbed.dtype == internal_dtype

        shape = original.shape

        min_, max_ = bounds

        # ===========================================================
        # draw a random direction
        # ===========================================================
github bethgelab / foolbox / foolbox / attacks / boundary_attack.py View on Github external
spherical_step,
        source_step,
        internal_dtype,
        rng=None,
    ):

        if rng is None:
            try:
                import randomgen
            except ImportError:  # pragma: no cover
                raise ImportError(
                    "To use the BoundaryAttack,"
                    " please install the randomgen"
                    " module (e.g. pip install randomgen)"
                )
            rng = randomgen.RandomGenerator()

        # ===========================================================
        # perform initial work
        # ===========================================================

        assert original.dtype == internal_dtype
        assert perturbed.dtype == internal_dtype

        shape = original.shape

        min_, max_ = bounds

        # ===========================================================
        # draw a random direction
        # ===========================================================
github bethgelab / foolbox / foolbox / attacks / boundary_attack.py View on Github external
spherical_step,
        source_step,
        internal_dtype,
        rng=None,
    ):

        if rng is None:
            try:
                import randomgen
            except ImportError:  # pragma: no cover
                raise ImportError(
                    "To use the BoundaryAttack,"
                    " please install the randomgen"
                    " module (e.g. pip install randomgen)"
                )
            rng = randomgen.RandomGenerator()

        # ===========================================================
        # perform initial work
        # ===========================================================

        assert original.dtype == internal_dtype
        assert perturbed.dtype == internal_dtype

        shape = original.shape

        min_, max_ = bounds

        # ===========================================================
        # draw a random direction
        # ===========================================================