5 examples of 'np.random.seed' in Python

Every line of 'np.random.seed' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
266def seed(self):
267 import random
268 import numpy as np
269 import tensorflow as tf
270 self.flags.seed = self.flags.seed or np.random.randint(1000000)
271 random.seed(self.flags.seed)
272 np.random.seed(self.flags.seed)
Important

Use secure code every time

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

680def init_random(self):
681
682 """
683 desc:
684 Initializes the random number generators. For some reason, the numpy
685 random seed is not re-initialized when the experiment is started
686 again with the multiprocess runner, resulting in identical random
687 runs. The standard random module doesn't suffer from this problem.
688 But to be on the safe side, we now explicitly re-initialize the
689 random seed.
690
691 See also:
692
693 - <http://forum.cogsci.nl/index.php?p=/discussion/1441/>
694 """
695
696 import random
697 random.seed()
698 try:
699 # Don't assume that numpy is available
700 import numpy
701 numpy.random.seed()
702 except:
703 pass
24def set_random_seed(seed):
25 # set Python random seed
26 random.seed(seed)
27 # set NumPy random seed
28 np.random.seed(seed)
31def __init__(self, seed):
32 self._seed = seed
33 self._master_rng_fct = rand.RandomState(seed)
34 self._master_rng = lambda: self._master_rng_fct.randint(1, 2 ** 16)
36def set_seed_random(seed):
37 random.seed(seed)
38 np.random.seed(seed)
39 if chainer.cuda.available:
40 chainer.cuda.cupy.random.seed(seed)

Related snippets