6 examples of 'random function in python' in Python

Every line of 'random function in python' 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
46def mutate(code_l: iter, func: callable, rate: float):
47 for code in code_l:
48 if rate < random():
49 continue
50 index = randint(0, len(code) - 1)
51 code[index] = func(index)
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

38def f(_):
39 x = random() * 2 - 1
40 y = random() * 2 - 1
41 return 1 if x ** 2 + y ** 2 < 1 else 0
33def gen_random():
34 return random.random()
14def random(size):
15 return rand(*size)
46def get_random(nbytes):
47 random_hex = binascii.hexlify(os.urandom(nbytes))
48 return hex_to_long(random_hex)
15def rando():
16 return random.StrongRandom().randint(2, 20000000)

Related snippets