10 examples of 'python random seed' in Python

Every line of 'python 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
10def seed(self, value):
11 self.engine.seed(value)
12 self.distribution.reset()
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

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)
24def set_random_seed(seed):
25 # set Python random seed
26 random.seed(seed)
27 # set NumPy random seed
28 np.random.seed(seed)
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
34def seed(seed=None):
35 np.random.seed(seed)
22def get_random_seed():
23 """Generate a random int good for seeding RNG via `seed` function"""
24 return int(np.random.uniform()*(2**31-1))
47def seed(self, x = 0, y = 0, z = 0):
48 """Set the seed from (x, y, z).
49 These must be integers in the range [0, 256)."""
50 if not type(x) == type(y) == type(z) == type(0):
51 raise TypeError, 'seeds must be integers'
52 if not (0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256):
53 raise ValueError, 'seeds must be in range(0, 256)'
54 if 0 == x == y == z:
55 # Initialize from current time
56 import time
57 t = long(time.time() * 256)
58 t = int((t&0xffffff) ^ (t>>24))
59 t, x = divmod(t, 256)
60 t, y = divmod(t, 256)
61 t, z = divmod(t, 256)
62 # Zero is a poor seed, so substitute 1
63 self._seed = (x or 1, y or 1, z or 1)
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)
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)
140def set_seed(self, val):
141 """Set current PRNG seed."""
142 self._streams = {}
143 self._seed = val

Related snippets