choose random number python code example

Example 1: random number python

# generate random integer values
from random import randint

value = randint(0, 10)
print(value)

Example 2: python random number

from random import randint

print(randint(1,3))

#Possible Outputs#
#1
#2
#3

Example 3: how to generate a random number python

import random
n = random.randint(0,22)
print(n)

Example 4: how to get random number python

import random
minimum_int, maximum_int = 0, 10
random_number = random.randint(minimum_int, maximum_int)

Example 5: random picker in python

import random
#dictionary
x_dict = {30:60, 20:40,10:20}
key = random.choice(list(x_dict))
print (key)#if you want it to print 30, 20, or 10
print (x_dict[key])#if you want it to print 60, 40, or 20
print (key,"-", x_dict[key])# if you want to print 30 - 60, 20-40,or 10-20

Example 6: how to get a random number in python

def randnum(min, max):
    num = random.randint(a, b)
    return num
  randomnumber = randnum(0,10)
  print(randomnumber)
 #output: 5