5 examples of 'random number generator 1-12' in Python

Every line of 'random number generator 1-12' 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
14def random_number_generator():
15 ran_decimal = random.randint(1, 255)
16 return (ran_decimal, bin(ran_decimal), hex(ran_decimal))

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

110def gen():
111 return fmt_string % (random.randint(1, x), random.randint(1, y))
140def random_ints():
141 """ Returns a random integer from 0 to 100,000 """
142 return str(int(math.floor(random.random() * 100000)))
404def get_random_number_string(length=10, choices=string.digits, no_leading_zero=True):
405 first = random.choice(choices)
406 # if no_leading_zero, then force first number to be nonzero
407 while no_leading_zero and not int(first):
408 # keep picking until we get nonzero
409 first = random.choice(choices)
410 return first + ''.join(random.choice(choices) for __ in range(length - 1))
33def gen_random():
34 return random.random()

Related snippets