how to choose a random value from a list in python code example
Example 1: python list of random values
import random
randomlist = random.sample(range(10, 30), 5)
import numpy
random_float_array = numpy.random.uniform(75.5, 125.5, 2)
Example 2: python choose random element from list
import random
random.choice(list)
random.choices(list, k = 4)
random.sample(list, 4)
Example 3: python choose random sample from list
import random
sequence = [i for i in range(20)]
subset = random.sample(sequence, 5)
print(subset)
Example 4: pick a random number from a list in python
import random
numberList = [1,2,3,4,5]
print(random.choice(numberList))
Example 5: place a number randomly in a list python
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