def seed(self, seed=None): """Resets the state of the random number generator with a seed. .. seealso:: :func:`cupy.random.seed` for full documentation, :meth:`numpy.random.RandomState.seed <numpy.random.mtrand.RandomState.seed>` """ if seed is None: try: seed_str = binascii.hexlify(os.urandom(8)) seed = int(seed_str, 16) except NotImplementedError: seed = (time.time() * 1000000) % _UINT64_MAX else: if isinstance(seed, numpy.ndarray): seed = int(hashlib.md5(seed).hexdigest()[:16], 16) else: seed = int( numpy.asarray(seed).astype(numpy.uint64, casting='safe')) curand.setPseudoRandomGeneratorSeed(self._generator, seed) if (self.method not in (curand.CURAND_RNG_PSEUDO_MT19937, curand.CURAND_RNG_PSEUDO_MTGP32)): curand.setGeneratorOffset(self._generator, 0) self._rk_seed = seed
def __init__(self, seed=0): rng = curand.createGenerator(curand.CURAND_RNG_PSEUDO_PHILOX4_32_10) curand.setPseudoRandomGeneratorSeed(rng, seed) if (args.use_common_seed): self.offset = rank * lattice_slab_n * args.lattice_m // 2 curand.setGeneratorOffset(rng, self.offset) self._rng = rng
def seed(self, seed=None): """Resets the state of the random number generator with a seed. ..seealso:: :func:`cupy.random.seed` for full documentation, :meth:`numpy.random.RandomState.seed` """ if seed is None: try: seed_str = binascii.hexlify(os.urandom(8)) seed = numpy.uint64(int(seed_str, 16)) except NotImplementedError: seed = numpy.uint64(time.clock() * 1000000) else: seed = numpy.uint64(seed) curand.setPseudoRandomGeneratorSeed(self._generator, seed)
def seed(self, seed=None): """Resets the state of the random number generator with a seed. .. seealso:: :func:`cupy.random.seed` for full documentation, :meth:`numpy.random.RandomState.seed` """ if seed is None: try: seed_str = binascii.hexlify(os.urandom(8)) seed = numpy.uint64(int(seed_str, 16)) except NotImplementedError: seed = numpy.uint64(time.clock() * 1000000) else: if isinstance(seed, numpy.ndarray): seed = int(hashlib.md5(seed).hexdigest()[:16], 16) seed = numpy.asarray(seed).astype(numpy.uint64, casting='safe') curand.setPseudoRandomGeneratorSeed(self._generator, seed) curand.setGeneratorOffset(self._generator, 0) self.rk_seed = numpy.uint64(seed)