10 examples of 'random.randint' in Python

Every line of 'random.randint' 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
87def randomize( min, max ):
88 return random.randint( min, max )
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

16def randint(a, b):
17 return a + int(random.random() * (b + 1 - a))
15def rando():
16 return random.StrongRandom().randint(2, 20000000)
16def randint(self):
17 return random.randint(0, 999999999)
33def gen_random():
34 return random.random()
16def r(): return random.randint(0, 255)
171def rand_int(low, high):
172 return np.random.randint(low, high)
15def bigrandom():
16 return int(randy.random()*1000000)
154def pick_random(a, b):
155 a, b = map(convert_to_num, (a, b))
156 a, b = a[0], b[0]
157 if isinstance(a, float) or isinstance(b, float):
158 return random.uniform(a, b)
159 else:
160 return random.randint(a, b)
87def randrange(start, stop=None, step=1):
88 """Choose a random item from range(start, stop[, step]).
89
90 This fixes the problem with randint() which includes the
91 endpoint; in Python this is usually not what you want.
92
93 EXAMPLES:
94 sage: randrange(0, 100, 11)
95 11
96 sage: randrange(5000, 5100)
97 5051
98 sage: [randrange(0, 2) for i in range(15)]
99 [0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1]
100 sage: randrange(0, 1000000, 1000)
101 486000
102 sage: randrange(-100, 10)
103 -56
104 """
105 return _pyrand().randrange(start, stop, step)

Related snippets