xxxxxxxxxx
import random
#1.A single element
random.choice(list)
#2.Multiple elements with replacement
random.choices(list, k = 4)
#3.Multiple elements without replacement
random.sample(list, 4)
xxxxxxxxxx
import random
my_list = [1, 2, 3, 4, 5]
random_element = random.choice(my_list)
print(random_element)
xxxxxxxxxx
#import the random module
import random
my_list = ['apple', 'banana', 'orange', 'strawberry', 'mango']
#pick a random item from the list
print(random.choice(my_list))
xxxxxxxxxx
import random
# with replacement = same item CAN be chosen more than once.
# without replacement = same item CANNOT be chosen more then once.
# Randomly select 2 elements from list without replacement and return a list
random.sample(list_name, 2)
# Randomly select 3 elements from list with replacement and return a list
random.choices(set_name, k=3)
# Returns 1 random element from list
random.choice(list_name)
xxxxxxxxxx
import random
nums = ['a', 'b', 'c', 'd', 'e']
print(random.choice(nums))
xxxxxxxxxx
import random
# there are 2 ways for this
listofnum = [1, 2, 3, 4, 5]
# 1
print(random.choice(listofnum))
# 2
random.shuffle(listofnum)
print(listofnum)
xxxxxxxxxx
import random
my_list = [1, 2, 3, 4, 5]
random_element = random.choice(my_list)
print(random_element)
xxxxxxxxxx
import random
l = [0, 1, 2, 3, 4]
print(random.sample(l, 3))
# [1, 3, 2]
print(type(random.sample(l, 3)))
# <class 'list'>
xxxxxxxxxx
offsetBiasSample = [randint(-10,10)/100 for i in range(10)]
offsetBias = choice(offsetBiasSample)
index_offsetBias = randint(0,len(oldBiases)-1)
oldBiases[index_offsetBias] = oldBiases[index_offsetBias] + offsetBias