python choice random code example
Example 1: python random
import random
names = ['Harry', 'John', 'Smith', 'Larry']
print(random.choice(names))
print(random.randint(1, 100)
Example 2: python random
import random
print(random.randint(1, 100))
print(random.random())
Example 3: random.choice
import random
numberList = [111,222,333,444,555]
print("random item from list is: ", random.choice(numberList))
Example 4: random picker in python
import random
x_dict = {30:60, 20:40,10:20}
key = random.choice(list(x_dict))
print (key)
print (x_dict[key])
print (key,"-", x_dict[key])
Example 5: select random value from list python
import random
random.sample(list_name, 2)
random.choices(set_name, k=3)
random.choice(list_name)
Example 6: random.choice()
import random
l=[1,2,3,4,5,6,7,8,9,0]
random.choice(l)
print(l);