How to use the randomgen.entropy.random_entropy 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 firedrakeproject / firedrake / firedrake / randomfunctiongen.py View on Github external
def seed(self, seed=None, inc=None):

                if self._comm.Get_size() == 1:
                    super(_Wrapper, self).seed(seed=seed, inc=0 if inc is None else inc)
                else:
                    rank = self._comm.Get_rank()
                    if seed is None:
                        if rank == 0:
                            # generate a 128bit seed
                            entropy = randomgen.entropy.random_entropy(4)
                            seed = sum([int(entropy[i]) * 2 ** (32 * i) for i in range(4)])
                        else:
                            seed = None
                        # All processes have to have the same seed
                        seed = self._comm.bcast(seed, root=0)
                    # Use rank to generate multiple streams.
                    # If 'inc' is to be passed, it is users' responsibility
                    # to provide an appropriate value.
                    inc = inc or rank
                    super(_Wrapper, self).seed(seed=seed, inc=inc)