random number generator python in range code example
Example 1: python how to generate random number in a range
import random
x = random.random()
x = random.randint()
x = random.randint(1, 100)
Example 2: 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 3: random range python
from random import randrange
print(randrange(10))
Example 4: python random integer in range
import random
print(random.randint(0,9))
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